﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Net;
using System.IO;
using CCWin;
using Newtonsoft.Json;
using LitJson;
using Newtonsoft.Json.Linq;

namespace weiqijiance
{
    public partial class mainform : CCSkinMain
    {

        public bool sfOBD = false;//是否上传OBD


        public 信号处理模块.DACcontrol DAC = new 信号处理模块.DACcontrol();

       
        private SerialPort comBPQ = new SerialPort();//变频器


        public 控制流程.flowcrtl flowwq = new 控制流程.flowcrtl();//尾气流程控制，只用于灯牌提示
        //private SerialPort comLED = new SerialPort();//灯牌串口

       
        //private SerialPort comOBD = new SerialPort();//温度串口
        
        private StringBuilder builder = new StringBuilder();//避免在事件处理方法中反复的创建，定义到外面。  

        public bool bdiaodu = false;
       

        public float m_fAIBrData_L = 0;//左重量
        public float m_fAIBrData_R = 0;//右重量
        public int m_fBrLAI = 0;//整备质量左第几路
        public int m_fBrRAI = 0;//整备质量右第几路


        public static string shphm;
        public static string shpzl;

        public static string businessId;
        public static string registCode;
        public static string methodId = "";
        public static string obdzt = "";
        public double shuchutest;
       
        /// <summary>
        /// 数据库配置
        public static string sDataBaseIp;
        public static string sDataBaseName;
        public static string sDataBaseUserName;
        public static string sDataBasePwd;
        ////
        //检定系数
        ///
        public float m_fneizu = 0;//内阻
        public float m_fguanliang = 0;//惯量
        public float m_fhejiazai = 0;//恒加载
        public float m_fbianjiazai = 0;//变加载

        ///
        /// 限值变量

        public string szdksjc;//自动开始检测
        
        ///
        /// 联网内容
        public string sconnetname;
        public string surl;
        public string surl2;
        public string cityCode;
        public string stationCode;
        public string lineCode;
        public string StationCode;
        public string LWuser;
        public string LWpwd ;

        public string tongdaoqian;
        public string tongdaozhong;
        public string tongdaohou;
        public string wjlj;
        public string wjljxn;
        //主表上传信息
        public string VLPN;
        public string VLPNColor;
        public string svlpn;
        public string VIN;
        public string InspectionOperator;
        public string InspectionDriver;

        public string InspectionWay;
        public string InspectionNature;
        public string InspectionTimes;
        public string TSM;
        public string DayAcceptanceNum;
        public string IUTID = "1";
        public bool bgas;
        public bool bsk;
        //主表上传信息



        public float  HCEL5025;
        public float COEL5025;
        public float NOEL5025;
        public float HCEL2540;
        public float COEL2540;
        public float NOEL2540;

        public float LICOL;
        public float LIHCL;
        public float HICOL;
        public float HIHCL;

        public float noxlimit;//NOX限值

        public float TypeApprovalLimits;
        public float InspectionLimits;

        public int EngineRatedSpeed;
        public string BenchmarkMass;


        //安检联网部分
        public static string  jylsh;
        public static string  jyjgbh;
       
       
        public static string  hpzl;
        public static string  hphm;
        public static string clsbdh;
       

        public static string ssfAJLW;//是否安检联网
        public static string sfAJLWmoto;//是否摩托车安检联网
        //摄像头通道
        public string ledfactory = "维科";


        public bool btest;
        public bool bzuihouyizhou;

       

        //



        ////
        //检定系数
        ///
      
        public float m_fguanliangSC = 0;//惯量

        public float m_fbianjiazaiSC = 0;//变加载


        public float m_fhejiazaiSC486 = 0;//恒加载
        public float m_fhejiazaiSC646 = 0;//恒加载
        public float m_fhejiazaiSC4812 = 0;//恒加载
        public float m_fhejiazaiSC6412 = 0;//恒加载
        public string sdpzdcj;
        public string swsd;
        public string sxhbxxy;
        public string szsxy;

        public string sxhbbb;//信号处理板型号
        public string sxhbbb2;//信号处理板型号

        public bool bcomsk;
        public bool bcomgas;
        
        public int igascount;

        /// <summary>
        /// 不透光对应变量
        /// </summary>
        
        //创建 1个客户端套接字 和1个负责监听服务端请求的线程  
        Thread threadclient = null;
        Socket socketclient = null;

        public string sjieshou;
        public bool bjieshou;

        public string swdcj;//温度生产厂家
        public string swenducom;

        //数据库中数据
       

        public string fenxiyiqiye, fenxiyiname, fenxiyidate, fenxiyiqiyeQY, fenxiyinameQY, fenxiyidateQY, fenxiyiqiyeCY, fenxiyinameCY, fenxiyidateCY, dipanqiye, dipanname, OBDqiye, OBDname;
        public string sqysbbh;
        public string scysbbh;
        public string sdpcgjsbbh;
        public string sobdsbbh;

        public int iDAcount;

        public string jcffdh;//长沙平台检测方法代号
        public string odometer;//长沙平台里程表读数
        public string testtimes;//长沙平台检测次数
        public string testtype;//检测方法
        public string organ;
        public string jkxlh;

        public string slicense;
        public string slicensecode;
        public string jccs;
        public string neishenyuan;
        public string zhiliangkzy;



        public string OBD_jqmkd="0";
        public string OBD_fh = "0";
        public string OBD_qycgqxh = "0";
        public string OBD_glkqxs = "0";
        public string OBD_ymkd = "0";
        public string OBD_cs = "0";
        public string OBD_fdjzs = "0";
        public string OBD_jql = "0";
        public string OBD_jqyl = "0";
        public string OBD_scgl = "0";
        public string OBD_zyyl = "0";
        public string OBD_hyl = "0";
        public string OBD_no = "0";
        public string OBD_nsbsl = "0";
        public string OBD_pqwd = "0";
        public string OBD_klbjqyc = "0";
        public string OBD_egrkd = "0";
        public string OBD_rypsyl = "0";

        public bool  bcdjc = false;//主体函数是否重叠检测   
        public bool bsdb = false;//主体函数是否使用地磅  


        public string sfqycj = "";
        public string btgcj = "";



        [StructLayout(LayoutKind.Sequential)]
        public struct SystemTime
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort wHour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMiliseconds;
        }
        // 用于设置系统时间  
        [DllImport("Kernel32.dll")]
        public static extern bool SetLocalTime(ref SystemTime sysTime);
        // 用于获得系统时间  
        [DllImport("Kernel32.dll")]
        public static extern void GetLocalTime(ref SystemTime sysTime); 


        /// 
        /// </summary>
        /// <param name="crc"></param>
        /// <param name="by"></param>
        /// <returns></returns>

        public int CRC(int crc, byte by)
        {
            return (((crc) >> 8) ^ tabel[((crc) ^ (int)(by)) & 0XFF]);
        }

        static int[] tabel = { 0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241, 0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440, 0XCC01, 0X0CC0, 0X0D80, 0XCD41, 0X0F00, 0XCFC1, 0XCE81, 0X0E40, 0X0A00, 0XCAC1, 0XCB81, 0X0B40, 0XC901, 0X09C0, 0X0880, 0XC841, 0XD801, 0X18C0, 0X1980, 0XD941, 0X1B00, 0XDBC1, 0XDA81, 0X1A40, 0X1E00, 0XDEC1, 0XDF81, 0X1F40, 0XDD01, 0X1DC0, 0X1C80, 0XDC41, 0X1400, 0XD4C1, 0XD581, 0X1540, 0XD701, 0X17C0, 0X1680, 0XD641, 0XD201, 0X12C0, 0X1380, 0XD341, 0X1100, 0XD1C1, 0XD081, 0X1040, 0XF001, 0X30C0, 0X3180, 0XF141, 0X3300, 0XF3C1, 0XF281, 0X3240, 0X3600, 0XF6C1, 0XF781, 0X3740, 0XF501, 0X35C0, 0X3480, 0XF441, 0X3C00, 0XFCC1, 0XFD81, 0X3D40, 0XFF01, 0X3FC0, 0X3E80, 0XFE41, 0XFA01, 0X3AC0, 0X3B80, 0XFB41, 0X3900, 0XF9C1, 0XF881, 0X3840, 0X2800, 0XE8C1, 0XE981, 0X2940, 0XEB01, 0X2BC0, 0X2A80,
            0XEA41, 0XEE01, 0X2EC0, 0X2F80, 0XEF41, 0X2D00, 0XEDC1, 0XEC81, 0X2C40, 0XE401, 0X24C0, 0X2580, 0XE541, 0X2700, 0XE7C1, 0XE681, 0X2640, 0X2200, 0XE2C1, 0XE381, 0X2340, 0XE101, 0X21C0, 0X2080, 0XE041, 0XA001, 0X60C0, 0X6180, 0XA141, 0X6300, 0XA3C1, 0XA281, 0X6240, 0X6600, 0XA6C1, 0XA781, 0X6740, 0XA501, 0X65C0, 0X6480, 0XA441, 0X6C00, 0XACC1, 0XAD81, 0X6D40, 0XAF01, 0X6FC0, 0X6E80, 0XAE41, 0XAA01, 0X6AC0, 0X6B80, 0XAB41, 0X6900, 0XA9C1, 0XA881, 0X6840, 0X7800, 0XB8C1, 0XB981, 0X7940, 0XBB01, 0X7BC0, 0X7A80, 0XBA41, 0XBE01, 0X7EC0, 0X7F80, 0XBF41, 0X7D00, 0XBDC1, 0XBC81, 0X7C40, 0XB401, 0X74C0, 0X7580, 0XB541, 0X7700, 0XB7C1, 0XB681, 0X7640, 0X7200, 0XB2C1, 0XB381, 0X7340, 0XB101, 0X71C0, 0X7080, 0XB041, 0X5000, 0X90C1, 0X9181, 0X5140, 0X9301, 0X53C0, 0X5280, 0X9241, 0X9601, 0X56C0, 0X5780, 0X9741, 0X5500, 0X95C1, 0X9481, 0X5440,0X9C01, 0X5CC0, 0X5D80, 0X9D41, 0X5F00, 0X9FC1, 0X9E81, 0X5E40, 0X5A00, 0X9AC1, 0X9B81, 0X5B40, 0X9901, 0X59C0, 0X5880, 0X9841, 0X8801, 0X48C0, 0X4980, 0X8941, 0X4B00, 0X8BC1, 0X8A81, 0X4A40, 0X4E00, 0X8EC1, 0X8F81, 0X4F40, 0X8D01, 0X4DC0, 0X4C80, 0X8C41, 0X4400, 0X84C1, 0X8581, 0X4540, 0X8701, 0X47C0, 0X4680, 0X8641, 0X8201, 0X42C0, 0X4380, 0X8341, 0X4100, 0X81C1, 0X8081, 0X4040 };

        int CalcCRC(byte[] data, int size)
        {
            int i;
            int crc = 0;
            for (i = 8; i < size; i++)
            {
                crc = CRC(crc, data[i]);
            }
            return crc;

             
        }
        public bool openCOM(string sSet1, SerialPort commex)//打开串口
        {

            string[] szbzlCOM = new string[5];
            if (sSet1.Length > 0)
                szbzlCOM = sSet1.Split(':');
            //打开串口
            commex.PortName = szbzlCOM[0];
            commex.BaudRate = Convert.ToInt32(szbzlCOM[1]);
       
            commex.NewLine = "/r/n";
            commex.RtsEnable = true;//根据实际情况吧。 
            commex.ReadTimeout = 300;//读取数据延时，避免读取不全数据

            if (szbzlCOM[3] == "0")
                commex.Parity = Parity.None;
            else
                commex.Parity = Parity.Even;
            // ////添加事件注册  
            //  comm.DataReceived += comm_Data;
            try
            {
                commex.Open();
            }
            catch (Exception )
            {
               //lzj20200706 MessageBox.Show(string.Format("{0}\n请检查电脑的串口故障", ex.Message));
                return false;
            }
            return true;
        }
        public bool CloseCOM(SerialPort commex)//关闭串口
        {
            //关闭串口
            if (commex.IsOpen)
            {
                commex.Close();
                return true;
            }
            return true;
        }
        public string sczyxx = "";
       
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;

        public CDataClass dataBD;//获取标定数据及调零使用
        public Thread t1;
        public Thread t2;
        public Thread t3;
        public static bool bxtjs;//系统关闭结束
        public bool bzdcx;//调度自动查询

        public CCRC16Class CRC16;//


        /// <summary>
        /// 废气仪器对应变量
        /// </summary>
        ///
       

        public double dshuchu;//模块门槛值 
        public float f100dian;//全负荷扫描100点控制系数
        public float f90dian;//全负荷扫描100点控制系数
        public float f80dian;//全负荷扫描100点控制系数

        /// <summary>
        /// 转速仪对应变量
        /// </summary>
        //public int m_iTurn;//设备上变量

        /// <summary>
        /// 标定曲线对应变量
        /// </summary>
        ///  

        public float[] m_Datamonifr1;
        public float[] m_Datamonifs1;

        public float[] m_Datamonifr2;
        public float[] m_Datamonifs2;

        public float[] m_Datamonifr3;
        public float[] m_Datamonifs3;

        public float[] m_Datamonifr4;
        public float[] m_Datamonifs4;

        public float[] m_Datamonifr5;
        public float[] m_Datamonifs5;



        public float[] m_DataLiZfr;
        public float[] m_DataLiZfs;

        public float[] m_DataLiYfr;
        public float[] m_DataLiYfs;

        public float[] m_DataLiHfr;
        public float[] m_DataLiHfs;

        public float[] m_DataSpeedfr;
        public float[] m_DataSpeedfs;

        public bool[] bmoni;
        public bool[] bsudu;
        public bool[] bhongwai;
        public bool[] bkongzhi;
       


        public int itongdaoliZ;
        public int itongdaoliY;
        public int itongdaoliH;
        public int itongdaoSpeed;
        public short ijushengS;
        public short ijushengJ;
        public short ibianpinqi;
        public string sjjlukz;//举升是否两路控制


        public float m_fForce;//当前力
        public float m_fspeed;//当前速度
        //
        public float[] m_moni;//经过标定计算后出来的值
        public float[] m_sudu;//经过标定计算后出来的值
        public bool[] m_hongwai;//经过标定计算后出来的值


        public Button[] m_but;
        public string[] m_file;
        public bool bdushu;

        public bool bqyx = false;
        public bool bcyx = false;
        //protected override CreateParams CreateParams
        //{
        //    get
        //    {

        //        CreateParams cp = base.CreateParams;

        //        cp.ExStyle |= 0x02000000;

        //        return cp;

        //    }

        //}


        public mainform(string sid)
        {
            InitializeComponent();
            //SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
            sxhbxxy = "";//wwt
            //m_fnssk = 0;
            noxlimit = 0;//WT
            bzdcx = true;
            shuchutest = 900;
            registCode = sid;
            businessId = "";
            shouquama(sid);
            m_fForce = 0;
            m_fspeed = 0;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

        }
        public float fdiw = 0;
        public void readshezhiSBXX()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测设备信息设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            fenxiyiqiyeQY = ReadValue("检测设备信息", "汽油分析仪生产企业");
             fenxiyiqiyeCY= ReadValue("检测设备信息", "柴油分析仪生产企业");
            dipanqiye = ReadValue("检测设备信息", "底盘测功机生产企业");
            OBDqiye= ReadValue("检测设备信息", "OBD诊断仪生产企业");

            fenxiyinameQY = ReadValue("检测设备信息", "汽油分析仪名称");
            fenxiyinameCY = ReadValue("检测设备信息", "柴油分析仪名称");
            dipanname = ReadValue("检测设备信息", "底盘测功机型号");
            OBDname = ReadValue("检测设备信息", "OBD诊断仪型号");

            fenxiyidateQY = ReadValue("检测设备信息", "汽油分析仪检定日期");
           fenxiyidateCY = ReadValue("检测设备信息", "柴油分析仪检定日期");

           float.TryParse(ReadValue("检测设备信息", "台架惯量"), out fdiw);

           sqysbbh = ReadValue("检测设备信息", "汽油分析仪设备编号");
           scysbbh = ReadValue("检测设备信息", "柴油分析仪设备编号");
           sdpcgjsbbh = ReadValue("检测设备信息", "底盘测功机设备编号");
           sobdsbbh = ReadValue("检测设备信息", "OBD设备编号");

        }
        public void showFormUI()
        {
            try
            {
                this.BackgroundImage = Image.FromFile(@"./ico/主界面背景.jpg");
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
            catch
            {
            }
        }
        public void showUI()
        {
            try
            {
               
                for (int i = 0; i < 6; i++)
                {
                    buttton_pic(m_but[i], m_file[i]);
                }

            }
            catch
            {

            }
        }
        public void buttton_pic(Button but, string sfile)//控件显示风格
        {
            but.BackgroundImage = Image.FromFile(string.Format(@"{0}", sfile));
            but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            but.ImageAlign = ContentAlignment.TopLeft;
            but.TextAlign = ContentAlignment.TopRight;
            but.ForeColor = Color.Red;
            but.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); ;

        }
        public void shouquama(string sshouquanma)
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\授权码.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            Writue("授权码", "授权码1", sshouquanma);
        }
        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
       

        private void setControls(float newx, float newy, Control cons,int i)
        {
            //float fmin = Math.Min(newx, newy);
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    if (mytag.Length < 2)
                        continue;
                    float a = Convert.ToSingle(mytag[0]) * newx;
                    con.Width = (int)a;
                    a = Convert.ToSingle(mytag[1]) * newy;
                    con.Height = (int)(a);
                    //if (i == 1)
                    {
                        a = Convert.ToSingle(mytag[2]) * newx;
                        con.Left = (int)(a);
                        a = Convert.ToSingle(mytag[3]) * newy;
                    con.Top = (int)(a);
                    }
                    Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
                    if (currentSize <= 0)
                    {
                        currentSize = 0.1f;
                    }
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con,2);
                    }
                }
            }

        }
        #endregion

     
        public bool InsertDBquxian(string sql, byte[] bt)
        {
            if (sDataBaseIp.Length < 1)
                return false;
            string connectstr = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3};", sDataBaseIp, sDataBaseName, sDataBaseUserName, sDataBasePwd);
            SqlConnection sqlcnn = new SqlConnection(connectstr);
            //try
            {
                //打开数据库
                sqlcnn.Open();
                SqlCommand cmd = new SqlCommand(sql, sqlcnn);
                cmd.Parameters.AddWithValue("@vaxbrimage", bt);
                //执行插入操作，并返回受影响的行数
                int i = cmd.ExecuteNonQuery();
                //如果受影响的行数小于一则说明操作失败了
                if (i < 1)
                    return false;
                //关闭数据库
                sqlcnn.Close();
            }
            //catch (Exception er)
            //{
            //    string temp = er.Message.ToString();
            //    MessageBox.Show(temp);
            //    return false;
            //}
            return true;
        }
     
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件
        public void openallcom()//打开所有配置的串口
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
           
           sfqycj = ReadValue("串口设置", "废气仪厂家");
           btgcj = ReadValue("串口设置", "不透光厂家");
           sxhbxxy = ReadValue("通道设置", "信号板新协议");
           sxhbbb = ReadValue("通道设置", "信号板新协议版本");
           sxhbbb2 = ReadValue("通道设置", "信号板新协议版本2");
          
           szsxy = ReadValue("串口设置", "转速仪厂家");
            string sSetCom = ReadValue("串口设置", "信号处理模块");
            if (sSetCom != "")
            {
                //DAC.opencomm(sSetCom, 1, sxhbxxy == "是" ? true : false);
                DAC.opencomm(sSetCom, 1, sxhbbb);
                DAC.start();
            }

            string sxhbxxy2 = ReadValue("通道设置", "信号板新协议2");
            sSetCom = ReadValue("串口设置", "信号处理模块2");//第二块信号处理板
            if (sSetCom != "")
            {
                DAC.opencomm(sSetCom, 2, sxhbbb2);
                DAC.start();

            }

            sSetCom = ReadValue("串口设置", "变频器");
            if (sSetCom != "")
            {
                openCOM(sSetCom, comBPQ);
                comBPQ.ReadTimeout = 500;
                comBPQ.ReceivedBytesThreshold = 2;//达到50字节以后才开始触发串口
                comBPQ.DataReceived += comBPQ_DataReceived;
            }
            sSetCom = ReadValue("串口设置", "转速仪");
            if (sSetCom != "")
            {

                if (szsxy.Contains("鸣泉"))
                {
                    objzsy = new 转速仪.zsymq();

                }
                else if (szsxy.Contains("福立"))
                {
                    objzsy = new 转速仪.zsyfuli();
                }
                objzsy.openCOM(sSetCom);
               
            }
            bgas = false;
            sSetCom = ReadValue("串口设置", "废气仪");
            if (sSetCom != "")
            {
                bqyx = true;
                bgas = true;
                if (sfqycj.Contains("鸣泉50A"))
                {
                    objfqy = new 废气仪.fqy50a();
                    
                }
                else if (sfqycj.Contains("鸣泉50B"))
                {
                    objfqy = new 废气仪.fqy50b();
                }
                else if (sfqycj.Contains("翰创504"))
                {
                    objfqy = new 废气仪.fqymka504();
                }
                objfqy.openCOM(sSetCom);
               
            }
            objfqy.objzsy = objzsy;
            bsk = false;
            sSetCom = ReadValue("串口设置", "不透光仪");
            if (sSetCom != "")
            {
                bcyx = true;
                bsk = true;
                if (btgcj.Contains("鸣泉201"))
                {
                    objbtg = new 不透光.btgmqy201();

                }
                else if (btgcj.Contains("鸣泉5102"))
                {
                    objbtg = new 不透光.btgmingquan5102();
                }
                else if(btgcj.Contains("翰创503"))
                {
                    objbtg=new 不透光.hanchuang503();
                }
                objbtg.openCOM(sSetCom);
               
            }
            objbtg.objzsy = objzsy;
           
          

            sSetCom = ReadValue("串口设置", "环境温湿度");
            swenducom = sSetCom;
            swdcj = ReadValue("串口设置", "环境温湿度厂家");
            if (sSetCom != "")
            {
                bgas = true;
                
                
                if (swdcj.Contains("维柯"))
                {
                    objwsddqy = new 温湿度大气压.wsddqyweike();

                }
                else if (swdcj.Contains("福立"))
                {
                    objwsddqy = new 温湿度大气压.wsddqyfuli();
                }
                objwsddqy.openCOM(sSetCom);
                
            }
            objfqy.objwsddqy = objwsddqy;
            objbtg.objwsddqy = objwsddqy;

        }
        public void closeallcom()
        {
            //CloseCOM(comDA);
            CloseCOM(comBPQ);
            //CloseCOM(comGAS);
            //CloseCOM(comSK);
            //CloseCOM(comZS);
            //CloseCOM(comLED);
          //  t1.Abort();
          //  t1.DisableComObjectEagerCleanup();

           // t2.Abort();
           // t2.DisableComObjectEagerCleanup();
           
        }
        public void closeall()//关闭所有包括进程
        {
            System.Environment.Exit(0);
        }

        /// <summary>
        /// 发送指令给串口部分
        /// </summary>
        /// <param name="sneirong"></param>
      

        public void sendBPQcom(string sneirong)//发送指令给变频器串口
        {
            string hexValues = sneirong;
            string[] hexValuesSplit = hexValues.Split(' ');
            int icount = 100;
            icount = hexValuesSplit.Length;
            if (comBPQ.IsOpen)
            {
                Byte[] m_byte = new Byte[icount];
                for (int i = 0; i < icount; i++)
                {
                    m_byte[i] = (byte)Convert.ToInt32(hexValuesSplit[i], 16);
                }
                comBPQ.Write(m_byte, 0, icount);
            }
        }
       
      

        /// <summary>
        /// 发送指令给串口部分
        /// </summary>
        /// <param name="sneirong"></param>

     

        /// <summary>
        ///接收串口返回部分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
     


        void comBPQ_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            if (comBPQ.IsOpen)
            {

                int n = comBPQ.BytesToRead;//
                byte[] buf1 = new byte[n];//声明一个临时数组存储当前来的串口数据  
                byte[] buf = new byte[n];
                comBPQ.Read(buf1, 0, n);
                if (n > 47)
                {

                }
            }

        }

      

        /// <summary>
        ///接收串口返回部分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>



        /// <summary>
        /// 红外信号判断是否到位 路数 是否取反 保持稳定时间
        /// </summary>
        /// <param name="sName"></param>
        public void WaitEvent(int lushu, bool bqufan, int stime)
        {
            DateTime dstart = DateTime.Now;
            while(true)
            {
                Thread.Sleep(10);
                bool bzhuangtai =DAC.bDIData[lushu];
                if (bqufan)
                {
                    bzhuangtai = !bzhuangtai;
                }
                if (bzhuangtai)
                {
                    if (DateDiff(DateTime.Now, dstart) > stime)
                    {
                        break;
                    }
                }
                else
                {
                    dstart = DateTime.Now;
                }
            }
        }

        /// <summary>
        /// 红外信号判断是否到位 路数 是否取反 保持稳定时间
        /// </summary>
        /// <param name="sName"></param>
        public void WaitEventMJ(int lushu, bool bqufan, int stime)
        {
            //DateTime dstart = DateTime.Now;
            while (true)
            {
                Thread.Sleep(10);
                bool bzhuangtai =DAC.bDIData[lushu];
                if (bqufan)
                {
                    bzhuangtai = !bzhuangtai;
                }
                if (bzhuangtai)
                {
                    //if (DateDiff(DateTime.Now, dstart) > stime)
                    {
                        break;
                    }
                }
                //else
                //{
                //    dstart = DateTime.Now;
                //}
            }
        }
        public bool WaitEventZT(int lushu, bool bqufan, int stime)
        {
            bool bzhuangtai =DAC.bDIData[lushu];
            if (bqufan)
            {
                bzhuangtai = !bzhuangtai;
            }
            return bzhuangtai;
        }
      
        public bool WaitEventCF(int lushu, bool bqufan, int stime)//触发红外
        {
            DateTime dstart = DateTime.Now;
            while (true)
            {
                Thread.Sleep(10);
                bool bzhuangtai = DAC.bDIData[lushu];
                if (bqufan)
                {
                    bzhuangtai = !bzhuangtai;
                }
                if (bzhuangtai)
                {
                    if (DateDiff(DateTime.Now, dstart) > stime)
                    {
                        return true;
                    }
                }
                else
                {
                    dstart = DateTime.Now;
                    
                }
            }
          

        }

        public bool WaitEventCS(int lushu, bool bqufan, int stime)//触发红外
        {
            DateTime dstart = DateTime.Now;

            bool bzhuangtai = DAC.bDIData[lushu];
            if (bqufan)
            {
                bzhuangtai = !bzhuangtai;
            }
            if (bzhuangtai)
            {
                //if (DateDiff(DateTime.Now, dstart) > stime)
                {
                    return true;
                }
            }
            else
            {
                dstart = DateTime.Now;
                return false;
            }
           

        }


      


        public void getBDQXLiZ(string sName)//获取标定曲线力左
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\标定数据.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            string sSet;
            sSet = ReadValue("标定", sName);
            if (sSet.Length <= 0)
            {

                return;
            }
            string[] sbdsj = sSet.Split(';');
            string[] sbdfr = sbdsj[0].Split(',');
            string[] sbdfs = sbdsj[1].Split(',');
            m_DataLiZfr = new float[sbdfr.Length - 1];
            m_DataLiZfs = new float[sbdfr.Length - 1];
            for (int i = 0; i < sbdfr.Length - 1; i++)
            {
                m_DataLiZfr[i] = (float)Convert.ToDouble(sbdfr[i]);
                m_DataLiZfs[i] = (float)Convert.ToDouble(sbdfs[i]);
            }

            return;
        }
        public void getBDQXLiY(string sName)//获取标定曲线力右
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\标定数据.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            string sSet;
            sSet = ReadValue("标定", sName);
            if (sSet.Length <= 0)
            {

                return;
            }
            string[] sbdsj = sSet.Split(';');
            string[] sbdfr = sbdsj[0].Split(',');
            string[] sbdfs = sbdsj[1].Split(',');
            m_DataLiYfr = new float[sbdfr.Length - 1];
            m_DataLiYfs = new float[sbdfr.Length - 1];
            for (int i = 0; i < sbdfr.Length - 1; i++)
            {
                m_DataLiYfr[i] = (float)Convert.ToDouble(sbdfr[i]);
                m_DataLiYfs[i] = (float)Convert.ToDouble(sbdfs[i]);
            }

            return;
        }
        public void getBDQXLiH(string sName)//获取标定曲线力后
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\标定数据.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            string sSet;
            sSet = ReadValue("标定", sName);
            if (sSet.Length <= 0)
            {

                return;
            }
            string[] sbdsj = sSet.Split(';');
            string[] sbdfr = sbdsj[0].Split(',');
            string[] sbdfs = sbdsj[1].Split(',');
            m_DataLiHfr = new float[sbdfr.Length - 1];
            m_DataLiHfs = new float[sbdfr.Length - 1];
            for (int i = 0; i < sbdfr.Length - 1; i++)
            {
                m_DataLiHfr[i] = (float)Convert.ToDouble(sbdfr[i]);
                m_DataLiHfs[i] = (float)Convert.ToDouble(sbdfs[i]);
            }

            return;
        }
        public void getBDQXSpeed(string sName)//获取标定曲线速度
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\标定数据.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            string sSet;
            sSet = ReadValue("标定", sName);
            if (sSet.Length <= 0)
            {
                return;
            }
            string[] sbdsj = sSet.Split(';');
            string[] sbdfr = sbdsj[0].Split(',');
            string[] sbdfs = sbdsj[1].Split(',');
            m_DataSpeedfr = new float[sbdfr.Length - 1];
            m_DataSpeedfs = new float[sbdfr.Length - 1];
            for (int i = 0; i < sbdfr.Length - 1; i++)
            {
                m_DataSpeedfr[i] = (float)Convert.ToDouble(sbdfr[i]);
                m_DataSpeedfs[i] = (float)Convert.ToDouble(sbdfs[i]);
            }

            return;
        }
        public void getBDQXall()//加载获取所有标定曲线
        {
            getBDQXLiZ("力信号左");
            getBDQXLiY("力信号右");
            getBDQXLiH("力信号后");
            getBDQXSpeed("速度");
        }
        public void gettongdaoall()//获取所有信息通道
        {
           

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            string sSetTongDao = ReadValue("通道设置", "模拟信号1");
            if (sSetTongDao != "")
            {
                bmoni[0] = true;
            }
            sSetTongDao = ReadValue("通道设置", "模拟信号2");
            if (sSetTongDao != "")
            {
                bmoni[1] = true;
            }
            sSetTongDao = ReadValue("通道设置", "模拟信号3");
            if (sSetTongDao != "")
            {
                bmoni[2] = true;
            }
            sSetTongDao = ReadValue("通道设置", "模拟信号4");
            if (sSetTongDao != "")
            {
                bmoni[3] = true;
            }
            sSetTongDao = ReadValue("通道设置", "模拟信号5");
            if (sSetTongDao != "")
            {
                bmoni[4] = true;
            }
           
            sSetTongDao = ReadValue("通道设置", "速度1");
            if (sSetTongDao != "")
            {
                bsudu[0] = true;
            }
            sSetTongDao = ReadValue("通道设置", "速度2");
            if (sSetTongDao != "")
            {
                bsudu[1] = true;
            }

            sSetTongDao = ReadValue("通道设置", "红外1");
            if (sSetTongDao != "")
            {
                bhongwai[0] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外2");
            if (sSetTongDao != "")
            {
                bhongwai[1] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外3");
            if (sSetTongDao != "")
            {
                bhongwai[2] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外4");
            if (sSetTongDao != "")
            {
                bhongwai[3] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外5");
            if (sSetTongDao != "")
            {
                bhongwai[4] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外6");
            if (sSetTongDao != "")
            {
                bhongwai[5] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外7");
            if (sSetTongDao != "")
            {
                bhongwai[6] = true;
            }
            sSetTongDao = ReadValue("通道设置", "红外8");
            if (sSetTongDao != "")
            {
                bhongwai[7] = true;
            }


            sSetTongDao = ReadValue("通道设置", "举升1");
            if (sSetTongDao != "")
            {
                bkongzhi[0] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升2");
            if (sSetTongDao != "")
            {
                bkongzhi[1] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升3");
            if (sSetTongDao != "")
            {
                bkongzhi[2] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升4");
            if (sSetTongDao != "")
            {
                bkongzhi[3] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升5");
            if (sSetTongDao != "")
            {
                bkongzhi[4] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升6");
            if (sSetTongDao != "")
            {
                bkongzhi[5] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升7");
            if (sSetTongDao != "")
            {
                bkongzhi[6] = true;
            }
            sSetTongDao = ReadValue("通道设置", "举升8");
            if (sSetTongDao != "")
            {
                bkongzhi[7] = true;
            }
            for (int i = 0; i < 16; i++)
            {
                sSetTongDao = ReadValue("通道设置", string.Format("控制{0}",i+1));
                if (sSetTongDao != "")
                {
                    if (sSetTongDao.Contains("测功举升升"))
                    {
                        ijushengS = (short)i;
                    }
                    else if (sSetTongDao.Contains("测功举升降"))
                    {
                        ijushengJ = (short)i;
                    }
                    else if (sSetTongDao.Contains("变频器"))
                    {
                        ibianpinqi = (short)i;
                    }
                }
            }
          

            sjjlukz = ReadValue("通道设置", "举升两路控制");
            
        }
        public void readjcxx()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测参数设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);


            double.TryParse(ReadValue("设置", "输出模块门槛值"), out dshuchu);

            float.TryParse(ReadValue("设置", "全负荷扫描100点控制系数"), out f100dian);
            float.TryParse(ReadValue("设置", "全负荷扫描80点控制系数"), out f80dian);

           


        }

        public float GetValue(float[] m_Datafr, float[] m_Datafs, float fSourceData)//标定曲线的采样值和标准值 去掉零点后的采样值
        {
            if (m_Datafr == null)
            {
                return 0;
            }
            int nSize = m_Datafr.Length;
            if (nSize < 2) return 0;
            int i = 0;
            for (i = 0; i < nSize; i++)
            {
                if (fSourceData < m_Datafr[i])
                    break;
            }

            float fValue;
            i = System.Math.Max(1, i);
            i = System.Math.Min(nSize - 1, i);

            fValue = m_Datafs[i - 1]
                + (fSourceData - m_Datafr[i - 1])
                * (m_Datafs[i] - m_Datafs[i - 1])
                / (m_Datafr[i] - m_Datafr[i - 1]);
            fValue = (float)((int)(fValue * 10000)) / 10000;
            return fValue;
        }

        public void getSQLSZ()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\数据库设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            sDataBaseIp = ReadValue("设置", "数据库IP");
            sDataBaseName = ReadValue("设置", "数据库名称");
            sDataBaseUserName = ReadValue("设置", "用户");
            sDataBasePwd = ReadValue("设置", "密码");


        }

        public void readshezhiLW()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\联网信息设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            sconnetname = ReadValue("设置", "联网厂家");
            surl = ReadValue("设置", "联网地址");
            surl2 = ReadValue("设置", "联网地址2");
            cityCode = ReadValue("设置", "城市行政区划编码");
            stationCode = ReadValue("设置", "检测站编号");
            organ = stationCode;// "43011241";
            jkxlh = cityCode;// "E9C7038360D319F2183EEE49469871D4";

            lineCode = ReadValue("设置", "检测线编号");
            registCode = jkxlh;//lzj20200421 测试序列号和启动授权码一直
            tongdaoqian = ReadValue("设置", "工位前通道");
            tongdaozhong = ReadValue("设置", "工位中通道");
            tongdaohou = ReadValue("设置", "工位后通道");
            wjlj = ReadValue("设置", "文件路径");
            wjljxn = ReadValue("设置", "文件虚拟路径");
            neishenyuan = ReadValue("设置", "审核员");
            zhiliangkzy = ReadValue("设置", "质量控制员");

            LWuser = ReadValue("设置", "用户名");
            LWpwd = ReadValue("设置", "密码");
        }
        public void readshezhiJD()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检定系数设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            float.TryParse(ReadValue("设置", "内阻系数"), out m_fneizu);
            float.TryParse(ReadValue("设置", "惯量系数"), out m_fguanliang);
            float.TryParse(ReadValue("设置", "恒加载系数"), out m_fhejiazai);
            float.TryParse(ReadValue("设置", "变加载系数"), out m_fbianjiazai);



            m_fneizu = 1;
            m_fguanliang = 1;
            m_fhejiazai = 1;
            m_fbianjiazai = 1;
            float.TryParse(ReadValue("设置", "惯量输出系数"), out m_fguanliangSC);

            float.TryParse(ReadValue("设置", "恒加载系数"), out m_fhejiazaiSC4812);
            float.TryParse(ReadValue("设置", "恒加载系数"), out m_fhejiazaiSC6412);
            float.TryParse(ReadValue("设置", "恒加载系数"), out m_fhejiazaiSC486);
            float.TryParse(ReadValue("设置", "恒加载系数"), out m_fhejiazaiSC646);

            float.TryParse(ReadValue("设置", "变加载系数"), out m_fbianjiazaiSC);
        }


        
        /// <summary>
        /// 仪器指令封装函数
        /// </summary>
      


        public void BianPinQi(bool uStates)
        {
            if (uStates)
            {
                for (int i = 0; i < 2; i++)
                {
                    DAC.SetDOBit(ibianpinqi, 1);
                    Thread.Sleep(200);
                }
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    DAC.SetDOBit(ibianpinqi, 0);
                    Thread.Sleep(200);
                }
            }
        }

        public void BianPinQiSpeed(int ipinlv)//将变频器加速到频率
        {
            byte[] pData = new byte[11] { 0x01, 0x10, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x01, 0x67, 0x90 };//启动指令
            if (comBPQ.IsOpen)
            {
                comBPQ.Write(pData, 0, 11);
            }
            Thread.Sleep(1000);
            int iOutPut = ipinlv;
           

            int i11 = iOutPut / 256;
            int i12 = iOutPut % 256;

            byte[] Buff = new byte[11] { 0x01, 0x10, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x01, 0x00, 0x00 };//频率指令
            Buff[0] = 0x01;//从机地址，变频器

            Buff[1] = 0x10;//函数功能

            Buff[2] = 0x00;//起始地址 上位
            Buff[3] = 0x01;//起始地址 下位

            Buff[4] = 0x00;//个数 上位
            Buff[5] = 0x01;//个数 下位

            Buff[6] = 0x02;//数据数

            Buff[7] = (byte)i11;//其次数据 上位
            Buff[8] = (byte)i12;///其次数据 下位


            byte[] Buff16 = new byte[9] { 0x01, 0x10, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x01 };//频率指令
            Buff16[0] = 0x01;//从机地址，变频器

            Buff16[1] = 0x10;//函数功能

            Buff16[2] = 0x00;//起始地址 上位
            Buff16[3] = 0x01;//起始地址 下位

            Buff16[4] = 0x00;//个数 上位
            Buff16[5] = 0x01;//个数 下位

            Buff16[6] = 0x02;//数据数

            Buff16[7] = (byte)i11;//其次数据 上位
            Buff16[8] = (byte)i12;///其次数据 下位
            byte[] Buffxz= new byte[2] { 0x00, 0x00};
            Buffxz = weiqijiance.CCRC16Class.GetCRC16(Buff16, true);

            Buff[9] = Buffxz[0];//其次数据 上位
            Buff[10] = Buffxz[1];///其次数据 下位
            if (comBPQ.IsOpen)
            {
                comBPQ.Write(Buff, 0, 11);
            }


      




        }

     


        public void Thread1()//
        {

            //  for (; ; )
            DateTime dcomzs = DateTime.Now;
            while(bdushu)
            {
                objwsddqy.SendDeviceCmd();
                if (swenducom != "")
                {
                    Thread.Sleep(1000);
                    if (objwsddqy.m_fYaLi > 10 && objwsddqy.m_fYaLi < 150 && objwsddqy.m_fWenDu < 60 && objwsddqy.m_fShiDu < 100 && objwsddqy.m_fShiDu > 0)
                    {
                        updatehuanjing();
                    }
                }
                Thread.Sleep(2000);

            }
        }
        public void Thread2()
        {
            
        }
        DateTime timeobdgcstart = DateTime.Now;
        public void initobdgcsj()
        {
            OBD_jqmkd = "";
            OBD_fh = "";
            OBD_qycgqxh = "";
            OBD_glkqxs = "";
            OBD_ymkd = "";
            OBD_cs = "";
            OBD_fdjzs = "";
            OBD_jql = "";
            OBD_jqyl = "";
            OBD_scgl = "";
            OBD_zyyl = "";
            OBD_hyl = "";
            OBD_no = "";
            OBD_nsbsl = "";
            OBD_pqwd = "";
            OBD_klbjqyc = "";
            OBD_egrkd = "";
            OBD_rypsyl = "";
        }
        public bool getOBD_GCSJ(string sjylsh)//获取OBD过程数据信息
        {
            string sql;
            sql = string.Format(@"Select TOP (1) *  from OBD_GCSJ where jylsh='{0}' order by OBDGCSJ_ID ", sjylsh);
            DataTable dt = objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                timeobdgcstart = DateTime.Now;
                float fOBD_jqmkd = 0;
                float fOBD_fh = 0;
                float fOBD_qycgqxh = 0;
                float fOBD_glkqxs = 0;
                float fOBD_ymkd = 0;
                float fOBD_cs = 0;
                float fOBD_fdjzs = 0;
                float fOBD_jql = 0;
                float fOBD_jqyl = 0;
                float fOBD_scgl = 0;
                float fOBD_zyyl = 0;
                float fOBD_hyl = 0;
                float fOBD_no = 0;
                float fOBD_nsbsl = 0;
                float fOBD_pqwd = 0;
                float fOBD_klbjqyc = 0;
                float fOBD_egrkd = 0;
                float fOBD_rypsyl = 0;
                if (float.TryParse(dt.Rows[0]["jqmkd"].ToString().Trim(), out fOBD_jqmkd))
                { OBD_jqmkd = fOBD_jqmkd.ToString("0.00"); }
                else
                { OBD_jqmkd = ""; }
                if (float.TryParse(dt.Rows[0]["fh"].ToString().Trim(), out fOBD_fh))
                { OBD_fh = fOBD_fh.ToString("0.00"); }
                else
                { OBD_fh = ""; }
                if (float.TryParse(dt.Rows[0]["qycgqxh"].ToString().Trim(), out fOBD_qycgqxh))
                { OBD_qycgqxh = fOBD_qycgqxh.ToString("0.00"); }
                else
                { OBD_qycgqxh = ""; }
                if (float.TryParse(dt.Rows[0]["glkqxs"].ToString().Trim(), out fOBD_glkqxs))
                { OBD_glkqxs = fOBD_glkqxs.ToString("0.00"); }
                else
                { OBD_glkqxs = ""; }
                if (float.TryParse(dt.Rows[0]["ymkd"].ToString().Trim(), out fOBD_ymkd))
                { OBD_ymkd = fOBD_ymkd.ToString("0.00"); }
                else
                { OBD_ymkd = ""; }
                if (float.TryParse(dt.Rows[0]["cs"].ToString().Trim(), out fOBD_cs))
                { OBD_cs = fOBD_cs.ToString("0"); }
                else
                { OBD_cs = ""; }
                if (float.TryParse(dt.Rows[0]["fdjzs"].ToString().Trim(), out fOBD_fdjzs))
                { OBD_fdjzs = fOBD_fdjzs.ToString("0"); }
                else
                { OBD_fdjzs = ""; }
                if (float.TryParse(dt.Rows[0]["jql"].ToString().Trim(), out fOBD_jql))
                { OBD_jql = fOBD_jql.ToString("0.00"); }
                else
                { OBD_jql = ""; }
                if (float.TryParse(dt.Rows[0]["jqyl"].ToString().Trim(), out fOBD_jqyl))
                { OBD_jqyl = fOBD_jqyl.ToString("0.00"); }
                else
                { OBD_jqyl = ""; }
                if (float.TryParse(dt.Rows[0]["scgl"].ToString().Trim(), out fOBD_scgl))
                { OBD_scgl = fOBD_scgl.ToString("0.00"); }
                else
                { OBD_scgl = ""; }
                if (float.TryParse(dt.Rows[0]["zyyl"].ToString().Trim(), out fOBD_zyyl))
                { OBD_zyyl = fOBD_zyyl.ToString("0.00"); }
                else
                { OBD_zyyl = ""; }
                if (float.TryParse(dt.Rows[0]["hyl"].ToString().Trim(), out fOBD_hyl))
                { OBD_hyl = fOBD_hyl.ToString("0.00"); }
                else
                { OBD_hyl = ""; }
                if (float.TryParse(dt.Rows[0]["no"].ToString().Trim(), out fOBD_no))
                { OBD_no = fOBD_no.ToString("0"); }
                else
                { OBD_no = ""; }
                if (float.TryParse(dt.Rows[0]["nsbsl"].ToString().Trim(), out fOBD_nsbsl))
                { OBD_nsbsl = fOBD_nsbsl.ToString("0.00"); }
                else
                { OBD_nsbsl = ""; }
                if (float.TryParse(dt.Rows[0]["pqwd"].ToString().Trim(), out fOBD_pqwd))
                { OBD_pqwd = fOBD_pqwd.ToString("0.00"); }
                else
                { OBD_pqwd = ""; }
                if (float.TryParse(dt.Rows[0]["klbjqyc"].ToString().Trim(), out fOBD_klbjqyc))
                { OBD_klbjqyc = fOBD_klbjqyc.ToString("0.00"); }
                else
                { OBD_klbjqyc = ""; }
                if (float.TryParse(dt.Rows[0]["egrkd"].ToString().Trim(), out fOBD_egrkd))
                { OBD_egrkd = fOBD_egrkd.ToString("0.00"); }
                else
                { OBD_egrkd = ""; }
                if (float.TryParse(dt.Rows[0]["rypsyl"].ToString().Trim(), out fOBD_rypsyl))
                { OBD_rypsyl = fOBD_rypsyl.ToString("0.00"); }
                else
                { OBD_rypsyl = ""; }
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    OBD_jqmkd =     dt.Rows[0]["jqmkd"].ToString().Trim()
                //    OBD_fh =        dt.Rows[0]["fh"].ToString().Trim()
                //    OBD_qycgqxh =   dt.Rows[0]["qycgqxh"].ToString().Trim()
                //    OBD_glkqxs =    dt.Rows[0]["glkqxs"].ToString().Trim()
                //    OBD_ymkd =      dt.Rows[0]["ymkd"].ToString().Trim()
                //    OBD_cs =        dt.Rows[0]["cs"].ToString().Trim()
                //    OBD_fdjzs =     dt.Rows[0]["fdjzs"].ToString().Trim()
                //    OBD_jql =       dt.Rows[0]["jql"].ToString().Trim()
                //    OBD_jqyl =      dt.Rows[0]["jqyl"].ToString().Trim()
                //    OBD_scgl =      dt.Rows[0]["scgl"].ToString().Trim()
                //    OBD_zyyl =      dt.Rows[0]["zyyl"].ToString().Trim()
                //    OBD_hyl =       dt.Rows[0]["hyl"].ToString().Trim()
                //    OBD_no =        dt.Rows[0]["no"].ToString().Trim()
                //    OBD_nsbsl =     dt.Rows[0]["nsbsl"].ToString().Trim()
                //    OBD_pqwd =      dt.Rows[0]["pqwd"].ToString().Trim()
                //    OBD_klbjqyc =   dt.Rows[0]["klbjqyc"].ToString().Trim()
                //    OBD_egrkd =     dt.Rows[0]["egrkd"].ToString().Trim()
                //    OBD_rypsyl =    dt.Rows[0]["rypsyl"].ToString().Trim()
                //}
                //sql = string.Format(@"delete  from OBD_GCSJ where jylsh='{0}'", sjylsh);
                //objbass.objdb.InsertDB(sql);
                return true;
            }
            else if (!sfOBD)
            {
                return true;
            }
            //else if (!(sobdshifou == "1" || sfOBD))
            //{
            //    return true;
            //}
            else
            {
                if (DateTime.Now > timeobdgcstart.AddSeconds(5))
                {
                    return false;
                }
            }
            return true;
        }

     

        public void updatehuanjing()//更新环境参数信息
        {
            string sql;
            sql = string.Format(@"Select *  from HJXX where DETECT_ID=1 ");
            DataTable dt = objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update HJXX  set WenDu='{0}',ShiDu='{1}',YaLi='{2}'  where DETECT_ID=1 ", objwsddqy.m_fWenDu, objwsddqy.m_fShiDu, objwsddqy.m_fYaLi);
            }
            else
            {

                sql = string.Format(@"insert into HJXX (
                                               WenDu,
                                               ShiDu,
                                               YaLi,
                                                DETECT_ID) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                1)",
                                                objwsddqy.m_fWenDu,
                                                objwsddqy.m_fShiDu,
                                                objwsddqy.m_fYaLi);
            }
            objbass.objdb.InsertDB(sql);
        }

        public void updatesbxx(string slsh)//更新检测设备信息 更新检测线号
        {
            string sql;
            int DETECT_ID = 0;
            if (IsInt(slsh))
            {
                int.TryParse(slsh, out DETECT_ID);
            }

//            sql = string.Format(@"update ASMData  set fenxiyiqiye='{0}',
//                                fenxiyiname='{1}',
//                                fenxiyidate='{2}',
//                                dipanqiye='{3}',
//                                dipanname='{4}',
//                                OBDqiye='{5}',
//                                OBDname='{6}',
//                                DET_MDRIVE='{7}',
//                                ASM_CZY='{8}',
//                                ASM_JCX='{9}'
//                                where DETECT_ID={10} or ASM_JYLSH='{10}' ", fenxiyiqiye, fenxiyiname, fenxiyidate, dipanqiye, 
//                                                                        dipanname, OBDqiye, OBDname, skinCom_ycy.Text, skinCom_czy.Text,
//                                                                        lineCode,slsh);

            sql = string.Format(@"update Detects_SJE  set DET_XIANHAO='{0}'
                                where DETECT_ID={1} or ASM_JYLSH='{2}' ", lineCode, DETECT_ID, slsh);

            objbass.objdb.InsertDB(sql);
        }
        public void StartTest(string methodId)
        {

            updateODB(businessId);
            控制流程.flowcrtl.iquanjuzhuangtai = 1;
            if (methodId.Contains("DB") ||  methodId.Contains("双怠速"))//shaungdaishu双怠速
            {
                fenxiyiqiye=fenxiyiqiyeQY;
                fenxiyiname=fenxiyinameQY;
                fenxiyidate = fenxiyidateQY;
                updatesbxx(businessId);


                tishiSDS obj = new tishiSDS(businessId, registCode);
                obj.m_mainform = this;
                obj.ShowDialog();
            }
            else if (methodId.Contains("WT") || methodId.Contains("ASM"))//ASM
            {

                fenxiyiqiye = fenxiyiqiyeQY;
                fenxiyiname = fenxiyinameQY;
                fenxiyidate = fenxiyidateQY;
                updatesbxx(businessId);
                tishiASM obj = new tishiASM(businessId, registCode);
                obj.m_mainform = this;
                obj.ShowDialog();
            }
            else if (methodId.Contains("LD") || methodId.Contains("加载"))//LUG
            {
                fenxiyiqiye = fenxiyiqiyeCY;
                fenxiyiname = fenxiyinameCY;
                fenxiyidate = fenxiyidateCY;
                updatesbxx(businessId);
                tishiLUG obj = new tishiLUG(businessId, registCode);
                obj.m_mainform = this;
                obj.ShowDialog();
            }
            else if (methodId.Contains("TG") || methodId.Contains("自由"))//ZYJS
            {
                fenxiyiqiye = fenxiyiqiyeCY;
                fenxiyiname = fenxiyinameCY;
                fenxiyidate = fenxiyidateCY;
                updatesbxx(businessId);
                tishiZYJS obj = new tishiZYJS(businessId, registCode);
                obj.m_mainform = this;
                obj.ShowDialog();

            }

        }

        private void but_ASM_Click(object sender, EventArgs e)
        {
            //BiaoDing obj = new BiaoDing();
            //obj.m_mainform = this;
            //obj.ShowDialog();


            tishiASM obj = new tishiASM(businessId, registCode);
            obj.m_mainform = this;
            obj.MdiParent = this;
            obj.ShowDialog();

            //TESTASM obj = new TESTASM();
            //obj.m_mainform = this;
            //obj.ShowDialog();
        }

        private void but_compeizhi_Click(object sender, EventArgs e)
        {
         
            TongDaoSheZhi obj = new TongDaoSheZhi();
            obj.MdiParent = this.MdiParent;
           // obj.ShowDialog();
            obj.Show();
        }

        private void mainform_FormClosed(object sender, FormClosedEventArgs e)
        {
            bdushu = false;
            closeall();
            closeallcom();
        }

        private void but_biaoding_Click(object sender, EventArgs e)
        {
            BiaoDing obj = new BiaoDing();
            obj.m_mainform = this;
            obj.ShowDialog();
        }

        private void but_LUG_Click(object sender, EventArgs e)
        {
            tishiLUG obj = new tishiLUG(businessId, registCode);
            obj.m_mainform = this;
            obj.ShowDialog();
        }

        private void but_ZYJS_Click(object sender, EventArgs e)
        {
            tishiZYJS obj = new tishiZYJS(businessId, registCode);
            obj.m_mainform = this;
            obj.ShowDialog();

        }

        private void but_SDS_Click(object sender, EventArgs e)
        {

            tishiSDS obj = new tishiSDS(businessId, registCode);
            obj.m_mainform = this;
            obj.ShowDialog();
        }

        private void but_SBZJ_Click(object sender, EventArgs e)
        {
            shebeizijian obj = new shebeizijian();
            obj.m_mainform = this;
            obj.ShowDialog();
        }

        private void but_sheng_Click(object sender, EventArgs e)
        {
           
            DAC.Lift(true);

        }

        private void but_jian_Click(object sender, EventArgs e)
        {
            //SetDOBit(2, 0);
            //PutVol(0);
            //shuchutest = shuchutest + 50;
            DAC.Lift(false);
        }

      

        private void but_sx_Click(object sender, EventArgs e)
        {
           

           
        }
        public void sendUpInspectionSignal(string stationCode, string inspectionNum, string lineCode, string uniqueString, string startOrEnd)//发送开始
        {
            WebReference.VehicleInspectionService m_vesd = new WebReference.VehicleInspectionService();
            m_vesd.Url = surl;
            string str = m_vesd.UpInspectionSignal(stationCode, inspectionNum, lineCode, uniqueString, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), startOrEnd);
            if (str.Contains("false"))
            {
                MessageBox.Show(string.Format("开始与结束{0}", str));
            }
        }

        public void baocunCLXX(string hphm, string hpzl, string edgl, string edzs, string jzzl,string cllx,string rllx)
        {
            int zs = 0;
            int.TryParse(edzs, out zs);
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            Writue("设置", "车牌号码", hphm);
            Writue("设置", "号牌种类", hpzl);
            Writue("设置", "额定功率", edgl);
            Writue("设置", "额定转速", zs.ToString());
            Writue("设置", "基准质量", jzzl);
            Writue("设置", "车辆类型", cllx);
            Writue("设置", "燃料类型", rllx);
            

        }
       

        public string jzjskz="";
        public void jcyq()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            jzjskz = "是";// ReadValue("设置", "jzjskz");

        }
       
        public void insertjcwc(string slsh)//检测完成标志
        {
            objbass.insertjcwc(slsh);


        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //label_time.Text = "当前时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
       
       
       
       
        public void insertriji(string slsh,string sc,string fh,string lx)
        {
            string sqlrj = string.Format(@"insert into riji (
                                               InspectionNum,
                                                rj_sc,
                                                rj_fh,
                                                rj_date,
                                                rj_lx) values ('{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}')",
                                                slsh,
                                                sc,
                                                fh,
                                                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                lx);

            objbass.objdb.InsertDB(sqlrj);

        }


       

        private void button1_Click(object sender, EventArgs e)
        {
           


        }
       
       
        private void but_XXLR_Click(object sender, EventArgs e)
        {
            renyuanshezhi obj = new renyuanshezhi();
            obj.m_mainform = this;
            obj.MdiParent = this.MdiParent;
           // obj.ShowDialog();
            obj.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {


        }

         private void che_zdsx_CheckedChanged(object sender, EventArgs e)
         {
             
         }
         public double DateDiff(DateTime DateTime1, DateTime DateTime2)
         {
             double dateDiff = 0;
             TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
             dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
             return dateDiff;
         }
        //日记

        //
         private void but_lunzhong_Click(object sender, EventArgs e)
         {
            

           

           

         }
        ///安检联网部分
        ///

         public string decode(string str)//utf8转中文
         {
             Encoding utf8 = Encoding.UTF8;
             // 首先用utf-8进行解码                    
             return  HttpUtility.UrlDecode(str.ToUpper(), utf8);
         }
         public string encode(string str)//中文转utf8
         {
             Encoding utf8 = Encoding.UTF8;
             return  HttpUtility.UrlEncode(str, utf8);
         }


         public void baocunriji(string sname,string sneirong) //
         {
             try
             {
                 string syy = DateTime.Now.ToString("yyyy");
                 string smm = DateTime.Now.ToString("MM");
                 string sdd = DateTime.Now.ToString("dd");
                 string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                 if (!Directory.Exists(smul))
                 {
                     Directory.CreateDirectory(smul);
                 }
                 string path = "";
                 path = string.Format("{0}\\{1}.ini", smul, sname);

                 Ini(path);

                 Writue("日记", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), sneirong);
             }
             catch(Exception ex)
             {
                 SaveErrorLog("记录日记错误", ex.Message.ToString());
             }
         }

         public string writetext(string name, string scode, string shphm)
         {
             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}\\{4}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd, shphm);
             if (!System.IO.Directory.Exists(smul))
             {
                 System.IO.Directory.CreateDirectory(smul);
             }
             string lujing = string.Format(@"{0}/{1}.txt", smul, name);
             FileStream fs = new FileStream(lujing, FileMode.Create);
             StreamWriter sw = new StreamWriter(fs);
             sw.WriteLine(scode);
             sw.Flush();
             sw.Close();
             fs.Close();

             return "";
         }

         Random ran = new Random();
         public int getRandom(int imin, int imax)
         {
             return ran.Next(imin, imax);
         }
         public void connet()
         {
             //定义一个套接字监听  
             socketclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

             //获取文本框中的IP地址  
             IPAddress address = IPAddress.Parse("127.0.0.1");

             //将获取的IP地址和端口号绑定在网络节点上  
             IPEndPoint point = new IPEndPoint(address, 8098);

             try
             {
                 //客户端套接字连接到网络节点上，用的是Connect  
                 socketclient.Connect(point);

             }
             catch (Exception)
             {
                


                 return;
             }

             threadclient = new Thread(recv);
             threadclient.IsBackground = true;
             threadclient.Start();
         }

         // 接收服务端发来信息的方法    
         void recv()
         {
             //int x = 0;
             //持续监听服务端发来的消息 
             while (true)
             {
                 try
                 {
                     Thread.Sleep(10);
                     //定义一个1M的内存缓冲区，用于临时性存储接收到的消息  
                     byte[] arrRecvmsg = new byte[1024 * 1024];

                     //将客户端套接字接收到的数据存入内存缓冲区，并获取长度  
                     int length = socketclient.Receive(arrRecvmsg);

                     //将套接字获取到的字符数组转换为人可以看懂的字符串  
                     string strRevMsg = Encoding.UTF8.GetString(arrRecvmsg, 0, length);

                     sjieshou = (strRevMsg);
                     bjieshou = true;
                     //if (x == 1)
                     //{

                     //    Debug.WriteLine("服务器:" + GetCurrentTime() + "\r\n" + strRevMsg + "\r\n\n");
                     //}
                     //else
                     //{

                     //    Debug.WriteLine(strRevMsg + "\r\n\n");
                     //    x = 1;
                     //}
                 }
                 catch 
                 {
                    
                     break;
                 }
             }
         }

         //获取当前系统时间  
         DateTime GetCurrentTime()
         {
             DateTime currentTime = new DateTime();
             currentTime = DateTime.Now;
             return currentTime;
         }

         //发送字符信息到服务端的方法  
         void ClientSendMsg(string sendMsg)
         {
             //将输入的内容字符串转换为机器可以识别的字节数组     
             byte[] arrClientSendMsg = Encoding.UTF8.GetBytes(sendMsg);
             //调用客户端套接字发送字节数组     
             socketclient.Send(arrClientSendMsg);
             //将发送的信息追加到聊天内容文本框中     
            

         }

         private void tabPage3_Click(object sender, EventArgs e)
         {

         }


        

        

      

         private void skinBut_xxlr_Click(object sender, EventArgs e)
         {
             renyuanshezhi obj = new renyuanshezhi();
             obj.m_mainform = this;
             obj.MdiParent = this.MdiParent;
             // obj.ShowDialog();
             obj.Show();
         }

         private void skinBut_sbzj_Click(object sender, EventArgs e)
         {
             shebeizijian obj = new shebeizijian();
             obj.m_mainform = this;
             obj.ShowDialog();
         }

         private void skinBut_xhbd_Click(object sender, EventArgs e)
         {
             BiaoDing obj = new BiaoDing();
             obj.m_mainform = this;
             obj.ShowDialog();
         }

         private void skinBut_xxpz_Click(object sender, EventArgs e)
         {
             
                
            TongDaoSheZhi obj = new TongDaoSheZhi();
            obj.MdiParent = this.MdiParent;
            obj.setmainform(this);
           // obj.ShowDialog();
            obj.Show();
         }

         private void skinBut_jsj_Click(object sender, EventArgs e)
         {
             DAC.Lift(true);
         }

         private void skinButton1_Click(object sender, EventArgs e)
         {
             DAC.Lift(false);
         }

         private void skinBut_dd_Click(object sender, EventArgs e)
         {
             panel1.Visible = true;            
         }


         public void updateODB(string slsh)
         {
             int DETECT_ID = 0;
             if (IsInt(slsh))
             {
                 int.TryParse(slsh, out DETECT_ID);
             }
             string sqlsds = string.Format(@"update Detects_SJE set 
                                          [OBDxtgz]=1
                                          ,[OBDtx]=1
                                          ,[OBDtxbcg]=0
                                          ,[OBDbj]=1
                                          ,[OBDgzdm]=''
                                          ,[OBDjxzt]=1
                                          ,[OBDMIL]=''
                                          ,[OBDFDJCAL]=''
                                          ,[OBDFDJCVN]=''
                                          ,[OBDHCLCAL]=''
                                          ,[OBDHCLCVN]=''
                                          ,[OBDQTCAL]=''
                                          ,[OBDQTCVN]=''
                                          ,[OBDPD]=1 where DETECT_ID={0}  or ASM_JYLSH='{1}' ", DETECT_ID, slsh);
             objbass.objdb.InsertDB(sqlsds);
         }

         private void skinButton2_Click(object sender, EventArgs e)
         {
             guanyu obj = new guanyu();
             obj.ShowDialog();
         }

         private void skinBut_time_Click(object sender, EventArgs e)
         {
             //objbass.uploadimage(businessId);
             //if (sconnetname.Contains("安车"))
             //{
             //    objbass.gettime();
             //}
             //else if (sconnetname.Contains("云景"))
             //{
             //}
          //   getxianzhiCS();
                 objbass.gettime();
         }


         string LanChange(string str)
         {
             Encoding utf8;
             Encoding gb2312;
             utf8 = Encoding.GetEncoding("UTF-8");
             gb2312 = Encoding.GetEncoding("GB2312");
             byte[] gb = gb2312.GetBytes(str);
             gb = Encoding.Convert(gb2312, utf8, gb);
             return utf8.GetString(gb);
         }

         string ChangeLan(string text)
         {
             byte[] bs = Encoding.GetEncoding("UTF-8").GetBytes(text);
             bs = Encoding.Convert(Encoding.GetEncoding("UTF-8"), Encoding.GetEncoding("GB2312"), bs);
             return Encoding.GetEncoding("GB2312").GetString(bs);
         }
       
         public void getstandxzCS(string slsh, string stime)
         {
             if (!sconnetname.Contains("安车"))
             {
                 return;
             }





             


         }


         public void sendkaishiAC()
         {
             if (!sconnetname.Contains("安车"))
             {
                 return;
             }
             string vehispara = "";
             string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
             vehispara = stoubao + string.Format(@"<root><vehispara>
            <jylsh>{0}</jylsh>
				<testtimes>{1}</testtimes>
				<tsno>{2}</tsno>
				<testlineno>{3}</testlineno>
				<license>{4}</license>
				<licensecode>{5}</licensecode>
				<jcjsy>{6}</jcjsy>
				<jcczy>{7}</jcczy>
				<zlkzy>{8}</zlkzy>
				<sqr>{9}</sqr>
				<testtype>{10}</testtype>
				<odometer>{11}</odometer>
                <dqsj>{12}</dqsj>
                <jcbbh>{13}</jcbbh>
            </vehispara></root>", "",
                 "",
                 ""
                 );
         }
         public void sendjieshuAC(string result)
         {
             if (!sconnetname.Contains("安车"))
             {
                 return;
             }
             string vehisparajg = "";
             string stoubaojg = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
             stoubaojg = stoubaojg + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                      organ,
                                                     jkxlh,
                                                      "JS001");

             vehisparajg = stoubaojg + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <tsno>{2}</tsno>
                                <testlineno>{3}</testlineno>
                                <license>{4}</license>
			                    <licensecode>{5}</licensecode>
                                <result>{6}</result>
                                 </vehispara>
			                    </body>
                                </root>",
                                 businessId,
                                 testtimes,
                                 organ,
                                 lineCode,
                                 slicense,
                                 slicensecode,
                                 result);
             WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
             m_vesd.Url = surl;
             string sjg005 = decode(m_vesd.write(vehisparajg));
            

         }

         public void getpic(string zpbh)
         {
             if (sconnetname.Contains("安车"))
             {
                 string vehisparajg = "";
                 string stoubaojg = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
                 stoubaojg = stoubaojg + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                          organ,
                                                         jkxlh,
                                                          "ZP002");

                 vehisparajg = stoubaojg + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <tsno>{2}</tsno>
                                <testlineno>{3}</testlineno>
                                <zpbh>{4}</zpbh>
			                    <photo_date>{5}</photo_date>
                                 </vehispara>
			                    </body>
                                </root>",
                                     businessId,
                                     testtimes,
                                     organ,
                                     lineCode,
                                     zpbh,
                                     DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                 WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
                 m_vesd.Url = surl;
                 string sjg005 = decode(m_vesd.write(vehisparajg));
                 baocunriji(string.Format("照片{0}", sjg005));
             }
         }
         public void baocunRJ(string sname,string str) //
         {

             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
             if (!Directory.Exists(smul))
             {
                 Directory.CreateDirectory(smul);
             }
             string path = "";
             path = smul + string.Format("\\{0}.ini", sname);

             Ini(path);

             Writue("日志", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), str);
         }
         public void baocunriji(string str) //
         {

             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
             if (!Directory.Exists(smul))
             {
                 Directory.CreateDirectory(smul);
             }
             string path = "";
             path = smul + "\\返回日志.ini";

             Ini(path);

             Writue("日志", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), str);
         }


       

         public int panel_Width;
         public int panel_Height;

         public 联网通信协议.LWbass objbass = new 联网通信协议.LWbass();
         public 联网通信协议.LWbass objbassLW = new 联网通信协议.LWbass();
         public 联网通信协议.LWbass objbass3in1 = new 联网通信协议.LWbass();
         public 废气仪.fqybass objfqy = new 废气仪.fqybass();
         public 不透光.btgbass objbtg = new 不透光.btgbass();
         public 转速仪.zsybass objzsy = new 转速仪.zsybass();
         public 温湿度大气压.wsddqybass objwsddqy = new 温湿度大气压.wsddqybass();
         public  安检仪表.yibiaobass objyibiaobass = new 安检仪表.yibiaobass();

         public bool bsuozhi = true;
         private void mainform_Load(object sender, EventArgs e)
         {

            
         }

         public void Thread3()
         {
             Thread.Sleep(1000);
             DAC.tiaoling(1);
             //Thread.Sleep(1000);
         }
         public void iniform()
         {
             try
             {
                 objwsddqy.m_mainform = this;
                 readjcxx();
                 bdushu = true;
                 btest = true;
                 //stiaoma = "";
                 szdksjc = "是";
                 ssfAJLW = "否";
                 bmoni = new bool[5] { false, false, false, false, false };
                 bsudu = new bool[2] { false, false };
                 bhongwai = new bool[8] { false, false, false, false, false, false, false, false };
                 bkongzhi = new bool[8] { false, false, false, false, false, false, false, false };
                 m_moni = new float[5] { 0, 0, 0, 0, 0 };
                 m_sudu = new float[2] { 0, 0 };
                 m_hongwai = new bool[8] { false, false, false, false, false, false, false, false };
                 //fAIData = new float[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                 getSQLSZ();
                 readshezhiLW();
                 readshezhiJD();
                 jcyq();
                 bxtjs = false;
                 dataBD = new CDataClass();

                 getazjyb();
                 openallcom();
                 gettongdaoall();
                 getBDQXall();

                 readshezhiSBXX();

                 panel_Width = this.panel2.Width;
                 panel_Height = this.panel2.Height;
                 //check();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }

             objbass.setmainform(this);// = this;
             objbassLW = objbass;
             objbass3in1.setmainform(this);


             t2 = new Thread(new ThreadStart(Thread2));
             t2.Priority = ThreadPriority.Lowest;
             t2.Start();

             t1 = new Thread(new ThreadStart(Thread1));
             t1.Priority = ThreadPriority.BelowNormal;
             t1.Start();

             t3 = new Thread(new ThreadStart(Thread3));
             t3.Priority = ThreadPriority.BelowNormal;
             t3.Start();

             opengongwei();
         }

         public void getazjyb()
         {
             iniclass objini = new iniclass();
             string path = "";
             path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
             string path1 = string.Format(@"{0}", path);
             objini.Ini(path1);
             bcdjc = (objini.ReadValue("制动", "轴重制动重叠检测").Trim() == "1") ? true : false;
             bsdb = objini.ReadValue("整备质量", "地磅") == "是" ? true : false;
         
         }

         public string gb2312_xy(string sneirong)//校验位
         {
             string sjieguo = "";
             Encoding gb2312;

             gb2312 = Encoding.GetEncoding("GB2312");
             byte[] gb = gb2312.GetBytes(sneirong);
             if (gb.Length > 1)
             {
                 byte b = 0x00;
                 for (int i = 0; i < gb.Length; i++)
                 {
                     if (i < 1)
                     {
                         b = (byte)(gb[i] ^ 0x00);
                     }
                     else
                     {
                         b = (byte)(b ^ gb[i]);
                     }
                 }
                 sjieguo = string.Format("{0:D2}", Convert.ToString(b, 16)); ;

             }
             return sjieguo;

         }
        //


         public  void baocunrijiLI(string str)
         {
             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
             if (!Directory.Exists(smul))
             {
                 Directory.CreateDirectory(smul);
             }
             string path = "";
             path = smul + "\\力输出.ini";

             Ini(path);

             Writue("日志", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), str);
         }

         private string Encryption(string express)//加密
         {

             System.Text.Encoding encode = System.Text.Encoding.ASCII;
             byte[] bytedata = encode.GetBytes(express);
             return Convert.ToBase64String(bytedata, 0, bytedata.Length);
         }
         //
         private string Decrypt(string depress)//解密
         {

             byte[] outputb = Convert.FromBase64String(depress);
             return Encoding.Default.GetString(outputb);
         }

         private void skinBut_azj_Click(object sender, EventArgs e)
         {
            
         }

         public 数据库操作.dbbass objdbbass = new 数据库操作.dbbass();

         public string sjcbz = "21861";//检测标准
         public string sweburl = "";// objini.ReadValue("工位配置", "安检联网地址");
         public string sjcz = "";// objini.ReadValue("工位配置", "检测站编号");
         public string ssqm = "";// objini.ReadValue("工位配置", "授权码");
         public string ssqqzr = "";// objini.ReadValue("工位配置", "授权签字人");
         public string jcxdh = "";// objini.ReadValue("工位配置", "检测线")
         public string sfdbjcsj = "";//objini.ReadValue("工位配置", "检测时间是否达标")
         public string ycyzl = "";//引车员重量
         public int iycyzl = 0;//引车员重量
         public string dfjc = "";//加密狗标识
         public string web2 = ""; 

         public TESTSP flowsp;
         public TESTAP flowap;
         public TESTLI flowli;
         public TESTSL flowsl;
         public TESTWE flowwe;
         public TESTBR flowbr;
         public TESTDLX flowdlx;
         public TESTYH flowyh;
         public TESTSU flowsu;
         //public TESTNO flowno;
         public 安检仪表.TESTFL flowfl;
         public 安检仪表.TESTZBZL flowzbzl;
         //public 控制流程.socketserver objsocket = new 控制流程.socketserver();
         public 控制流程.socketserverUDP objsocket = new 控制流程.socketserverUDP();
         public List<控制流程.flowcrtl> listflow = new List<控制流程.flowcrtl>();
         public void opengongwei()
         {
             try
             {
                 //查询联网信息
                 objyibiaobass.f11.m_mainform = this;
                 string ssptongdao = "";// objini.ReadValue("工位配置", "车速抓拍通道");
                 string sdlxtongdao = "";// objini.ReadValue("工位配置", "车速抓拍通道");
                 string saptongdao = "";// objini.ReadValue("工位配置", "地沟抓拍通道");
                 string slitongdao = "";// objini.ReadValue("工位配置", "灯光抓拍通道");
                 string slitongdao2 = "";// objini.ReadValue("工位配置", "灯光抓拍通道");
                 string ssltongdao = "";// objini.ReadValue("工位配置", "侧滑抓拍通道");
                 string sbrtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string sbrtongdao2 = "";// objini.ReadValue("工位配置", "制动抓拍通道2");
                 string sbrtongdaojz = "";// objini.ReadValue("工位配置", "制动抓拍通道2");
                 string szbzlqtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string szbzlhtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string swkccqtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string swkcchtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string sdpjxytongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");

                 string spbzdqtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string spbzdhtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string slzgwtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string szczdtongdao = "";// objini.ReadValue("工位配置", "制动抓拍通道");


                 string sspjcd = "";// objini.ReadValue("工位配置", "车速抓拍通道");
                 string sapjcd = "";// objini.ReadValue("工位配置", "地沟抓拍通道");
                 string slijcd = "";// objini.ReadValue("工位配置", "灯光抓拍通道");
                 string ssljcd = "";// objini.ReadValue("工位配置", "侧滑抓拍通道");
                 string sbrjcd = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string szbzljcd = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string swkccjcd = "";// objini.ReadValue("工位配置", "制动抓拍通道");
                 string swejcd = "";// objini.ReadValue("工位配置", "侧滑抓拍通道");
                 string szcjcd = "";// objini.ReadValue("工位配置", "侧滑抓拍通道");




                 string lwpt = "";// objini.ReadValue("工位配置", "联网平台");
                 var sql = "";
                 sql = string.Format(@"SELECT * FROM StationInfor");
                 DataTable dt = objdbbass.GetTable(sql);
                 if (dt.Rows.Count > 0)
                 {
                     sjcbz = dt.Rows[0]["Standard"].ToString().Trim();
                     sweburl = dt.Rows[0]["SI_WEB"].ToString().Trim();
                     sjcz = dt.Rows[0]["SI_JCZBH"].ToString().Trim();
                     ssqm = dt.Rows[0]["SI_SQM"].ToString().Trim();
                     ssqqzr = dt.Rows[0]["SI_SQQZR"].ToString().Trim();
                     lwpt = dt.Rows[0]["SI_LWCJ"].ToString().Trim();
                     dfjc = dt.Rows[0]["SI_HPCSZ"].ToString().Trim();
                     ssfAJLW = dt.Rows[0]["SI_Networking"].ToString().Trim().Contains("True") ? "是" : "否";
                     try
                     {
                         sfAJLWmoto = dt.Rows[0]["SI_MotoNetworking"].ToString().Trim().Contains("True") ? "是" : "否";
                     }
                     catch
                     {
                         sfAJLWmoto = "否";
                     }
                     try
                     {
                         ycyzl = dt.Rows[0]["SI_ycyzl"].ToString().Trim();
                     }
                     catch
                     {
                         ycyzl = "0";
                     }
                     int.TryParse(ycyzl, out iycyzl);
                 }
                 else
                 {
                     baocunRJ("软件打开出错", "连接不上数据库联网设置表。如果已经配置。请重新启动软件！");
                     MessageBox.Show("连接不上数据库联网设置表。\r\n如果已经配置。请重新启动软件！");
                     //return;
                 }

                 iniclass objini = new iniclass();
                 string path = "";
                 path = System.Windows.Forms.Application.StartupPath + path + "\\工位配置.ini";
                 string path1 = string.Format(@"{0}", path);
                 objini.Ini(path1);

                 int zpdk = 0;
                 string zpid = objini.ReadValue("工位配置", "抓拍IP地址");
                 int.TryParse(objini.ReadValue("工位配置", "抓拍端口"), out zpdk);//cjm
                 jcxdh = objini.ReadValue("工位配置", "检测线");
                 web2 = objini.ReadValue("工位配置", "联网平台");
                 sfdbjcsj = objini.ReadValue("工位配置", "检测时间是否达标");
                 web2 = objini.ReadValue("工位配置", "联网平台");
                 //查询照片抓拍通道

                 sql = string.Format(@"select * from PhotoChannel where channel_line='{0}' order by channel_id", jcxdh);
                 dt = objdbbass.GetTable(sql);
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     var name = "";
                     name = dt.Rows[i]["channel_name"].ToString().Trim();
                     string sjcd = dt.Rows[i]["channel_sbbh"].ToString().Trim();
                     if (name.Contains("车速工位"))
                     {
                         sspjcd = sjcd;
                         ssptongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("底盘检查工位"))
                     {
                         sapjcd = sjcd;
                         saptongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name == ("灯光工位"))
                     {
                         slijcd = sjcd;
                         slitongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name == ("灯光工位2"))
                     {
                         slijcd = sjcd;
                         slitongdao2 = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("侧滑工位"))
                     {
                         ssljcd = sjcd;
                         ssltongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name == ("制动前"))
                     {
                         sbrjcd = sjcd;
                         sbrtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name == ("制动后"))
                     {
                         sbrjcd = sjcd;
                         sbrtongdao2 = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name == ("加载制动"))
                     {
                         sbrjcd = sjcd;
                         sbrtongdaojz = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("整备质量前"))
                     {
                         szbzljcd = sjcd;
                         szbzlqtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("整备质量后"))
                     {
                         szbzljcd = sjcd;
                         szbzlhtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("外廓尺寸前"))
                     {
                         swkccjcd = sjcd;
                         swkccqtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("外廓尺寸后"))
                     {
                         swkcchtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("动力性"))
                     {
                         sdlxtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("底盘间隙仪"))
                     {
                         sdpjxytongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("轮重工位"))
                     {
                         swejcd = sjcd;
                         slzgwtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("驻车制动"))
                     {
                         szcjcd = sjcd;
                         szczdtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("平板制动前"))
                     {
                         spbzdqtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }
                     else if (name.Contains("平板制动后"))
                     {
                         spbzdhtongdao = dt.Rows[i]["channel_no"].ToString().Trim();
                     }

                 }
                 //尾气灯牌
                 flowwq.sdpcomm = objini.ReadValue("尾气配置", "灯牌").Trim();
                 flowwq.ledfactory = objini.ReadValue("尾气配置", "灯牌厂家").Trim();
      
                 bool bdpgy = false;
                 //


                 bool bwkyzb = false;
                 iniclass objiniwq = new iniclass();
                 string path2 = "";
                 path2 = System.Windows.Forms.Application.StartupPath + path2 + "\\联网信息设置.ini";
                 string path3 = string.Format(@"{0}", path2);
                 objiniwq.Ini(path3);
                 string wqchanjia = objiniwq.ReadValue("设置", "联网厂家").Trim();
                 if (wqchanjia.Contains("中科"))
                 {
                     objyibiaobass.f11.上传OBD数据ToolStripMenuItem.Visible = true;
                 }


                 #region 读取工位配置
                 for (int i = 1; i <= 6; i++)
                 {
                     string section = "工位" + i.ToString() + "配置";
                     if (objini.ReadValue("工位" + i.ToString() + "配置", "启用") == "1")
                     {
                         string sdpcomm = objini.ReadValue("工位" + i.ToString() + "配置", "灯牌").Trim();
                         int icount = 0;

                         string scount = objini.ReadValue(section, "设备数");
                         int.TryParse(scount, out icount);
                         for (int j = 0; j < icount; j++)
                         {
                             //-------------
                             #region 获取设备信息（灯牌，设备名，工位名)
                             控制流程.flowcrtl flowex = new 控制流程.flowcrtl();
                             bool bbz = false;
                             foreach (控制流程.flowcrtl flow in listflow)
                             {
                                 if (sdpcomm == flow.sdpcomm)
                                 {
                                     flowex.sdpcomm = flow.sdpcomm;
                                     flowex.dpcomm = flow.dpcomm;
                                     bbz = true;
                                     break;
                                 }
                             }
                             if (!bbz)
                             {
                                 if (sdpcomm.Length > 1)
                                 {
                                     flowex.sdpcomm = sdpcomm;
                                     openCOM(flowex.sdpcomm, flowex.dpcomm);
                                     if (flowwq.sdpcomm == sdpcomm)
                                     {
                                         bdpgy = true;
                                         flowwq.dpcomm = flowex.dpcomm;
                                     }

                                 }
                             }
                             flowex.m_mainform = this;
                             //----------------------
                             flowex.ledfactory = objini.ReadValue("工位" + i.ToString() + "配置", "灯牌厂家").Trim();
                             flowex.ledpinghao = objini.ReadValue("工位" + i.ToString() + "配置", "屏号").Trim().Length < 1 ? "3" : objini.ReadValue("工位" + i.ToString() + "配置", "屏号").Trim();
                             flowwq.ledpinghao = flowex.ledpinghao;
                             string ssbs = objini.ReadValue(section, "设备" + (j + 1).ToString()).Trim();
                             flowex.sgongwei = objini.ReadValue(section, "工位名称").ToString().Trim(); ;
                             flowex.sshebei = ssbs;
                             listflow.Add(flowex);
                             flowex.LedWrite(flowex.sgongwei, "", 1);
                             #endregion
                             //--------------------------------

                             flowex.ssfAJLW = ssfAJLW;
                             flowex.ssfAJLWmoto = sfAJLWmoto;
                             flowex.sweburl = sweburl;
                             flowex.sjcz = sjcz;
                             flowex.ssqm = ssqm;
                             flowex.ssqqzr = ssqqzr;
                             flowex.lwpt = lwpt;
                             flowex.photosIP = zpid;
                             flowex.photosPort = zpdk;//cjm
                             flowex.sjcbz = sjcbz;
                             flowex.initajlw();
                             int.TryParse(ssptongdao, out flowex.isptongdao);
                             int.TryParse(sdlxtongdao, out flowex.idlxtongdao);
                             int.TryParse(saptongdao, out flowex.iaptongdao);
                             int.TryParse(slitongdao, out flowex.ilitongdao);
                             int.TryParse(slitongdao2, out flowex.ilitongdao2);
                             int.TryParse(ssltongdao, out flowex.isltongdao);
                             int.TryParse(sbrtongdao, out flowex.ibrtongdao);
                             int.TryParse(sbrtongdao2, out flowex.ibrtongdao2);
                             int.TryParse(sbrtongdaojz, out flowex.ibrtongdaojz);
                             int.TryParse(szczdtongdao, out flowex.ibrtongdaozc);
                             int.TryParse(szbzlqtongdao, out flowex.izbzlqtongdao);
                             int.TryParse(szbzlhtongdao, out flowex.izbzlhtongdao);
                             int.TryParse(swkccqtongdao, out flowex.iwkccqtongdao);
                             int.TryParse(swkcchtongdao, out flowex.iwkccthongdao);
                             int.TryParse(sdpjxytongdao, out flowex.idpjxytongdao);
                                          
                             int.TryParse(slzgwtongdao, out flowex.ilzgwtongdao);
                             int.TryParse(spbzdqtongdao, out flowex.ipbzdqtongdao);
                             int.TryParse(spbzdhtongdao, out flowex.ipbzdhtongdao);
                             
                             #region
                             if (ssbs.Contains("车速"))
                             {
                                 flowex.gwjysbbh = sspjcd;
                                 车速ToolStripMenuItem.Visible = true;
                                 车速ToolStripMenuItem1.Visible = true;
                                 flowsp = new TESTSP(panel_Width, panel_Height);
                                 flowsp.m_mainform = this;
                                 //flowsp.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.isp = 0;
                                 flowsp.flowbass = flowex;
                                 flowsp.init();
                                 flowsp.timerstart();
                                 objyibiaobass.bSP = true;
                                 objyibiaobass.f3 = flowsp;
                             }
                             if (ssbs.Contains("地沟"))
                             {
                                 flowex.gwjysbbh = sapjcd;
                                 地沟ToolStripMenuItem.Visible = true;
                                 地沟ToolStripMenuItem1.Visible = true;
                                 flowap = new TESTAP(panel_Width, panel_Height);
                                 flowap.m_mainform = this;
                                 //flowap.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.iap = 0;
                                 flowap.flowbass = flowex;
                                 flowap.initcom();
                                 flowap.timerstart();
                                 objyibiaobass.bAP = true;
                                 objyibiaobass.f4 = flowap;
                             }
                             if (ssbs.Contains("灯光"))
                             {
                                 flowex.gwjysbbh = slijcd;
                                 灯光ToolStripMenuItem.Visible = true;
                                 灯光ToolStripMenuItem1.Visible = true;
                                 flowli = new TESTLI(panel_Width, panel_Height);
                                 flowli.m_mainform = this;
                                 //flowli.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.ili = 0;
                                 flowli.flowbass = flowex;
                                 flowli.init();
                                 flowli.timerstart();
                                 objyibiaobass.bLI = true;
                                 objyibiaobass.f5 = flowli;
                             }
                             if (ssbs.Contains("侧滑"))
                             {
                                 flowex.gwjysbbh = ssljcd;
                                 侧滑ToolStripMenuItem.Visible = true;
                                 侧滑ToolStripMenuItem1.Visible = true;
                                 flowsl = new TESTSL(panel_Width, panel_Height);
                                 flowsl.m_mainform = this;
                                 //flowsl.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.isl = 0;
                                 flowsl.flowbass = flowex;
                                 flowsl.init();
                                 flowsl.timerstart();
                                 objyibiaobass.bSL = true;
                                 objyibiaobass.f6 = flowsl;
                             }
                             if (ssbs.Contains("轮重"))// || bcdjc)//||true)//问题 交叉检测
                             {
                                 flowex.gwjysbbh = swejcd;
                                 轮重ToolStripMenuItem.Visible = true;
                                 轮重ToolStripMenuItem1.Visible = true;
                                 flowwe = new TESTWE(panel_Width, panel_Height);
                                 flowwe.m_mainform = this;
                                 //flowwe.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.iwe = 0;
                                 flowwe.flowbass = flowex;
                                 flowwe.init();
                                 flowwe.timerstart();
                                 objyibiaobass.bWE = true;
                                 objyibiaobass.f7 = flowwe;
                             }
                             if (ssbs.Contains("制动"))
                             {
                                 flowex.gwjysbbhzc = szcjcd;
                                 flowex.gwjysbbh = sbrjcd;
                                 制动ToolStripMenuItem.Visible = true;
                                 制动ToolStripMenuItem1.Visible = true;

                                 flowbr = new TESTBR(panel_Width, panel_Height);
                                 flowbr.m_mainform = this;
                                 //flowbr.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.ibr = 0;
                                 flowbr.flowbass = flowex;
                                 flowbr.timerstart();
                                 objyibiaobass.bBR = true;
                                 objyibiaobass.f8 = flowbr;
                             }
                             if (ssbs.Contains("动力性"))
                             {
                                 动力性ToolStripMenuItem.Visible = true;
                                 动力性ToolStripMenuItem1.Visible = true;
                                 flowdlx = new TESTDLX(panel_Width, panel_Height);
                                 flowdlx.m_mainform = this;
                                 //flowdlx.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.idlx = 0;
                                 flowdlx.flowbass = flowex;
                                 flowdlx.timerstart();
                                 objyibiaobass.bDLX = true;
                                 objyibiaobass.f1 = flowdlx;
                                 objyibiaobass.f11.动力性ToolStripMenuItem.Visible = true;
                             }
                             if (ssbs.Contains("经济性"))
                             {
                                 油耗ToolStripMenuItem.Visible = true;
                                 燃油经济性ToolStripMenuItem.Visible = true;
                                 flowyh = new TESTYH(panel_Width, panel_Height);
                                 flowyh.m_mainform = this;
                                 //flowyh.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.iyh = 0;
                                 flowyh.flowbass = flowex;
                                 flowyh.timerstart();
                                 objyibiaobass.bYH = true;
                                 objyibiaobass.f2 = flowyh;
                                 objyibiaobass.f11.油耗ToolStripMenuItem.Visible = true;
                             }
                             if (ssbs.Contains("悬架"))
                             {
                                 悬架ToolStripMenuItem.Visible = true;
                                 悬架ToolStripMenuItem1.Visible = true;
                                 flowsu = new TESTSU(panel_Width, panel_Height);
                                 flowsu.m_mainform = this;
                                 //flowsu.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.isu = 0;
                                 flowsu.flowbass = flowex;
                                 flowsu.timerstart();
                                 objyibiaobass.bSU = true;
                                 objyibiaobass.f10 = flowsu;
                             }
                             if (ssbs.Contains("平板"))
                             {
                                 flowex.gwjysbbh = sbrjcd;
                                 平板制动ToolStripMenuItem.Visible = true;
                                 平板制动ToolStripMenuItem1.Visible = true;
                                 flowfl = new 安检仪表.TESTFL(panel_Width, panel_Height);
                                 flowfl.m_mainform = this;
                                 //flowfl.StartPosition = FormStartPosition.CenterParent;
                                 控制流程.gongwei.ifl = 0;
                                 flowfl.flowbass = flowex;
                                 flowfl.timerstart();
                                 objyibiaobass.bFL = true;
                                 objyibiaobass.f9 = flowfl;
                             }
                             if (ssbs.Contains("整备质量") || ssbs.Contains("外廓尺寸"))
                             {

                                 if (bwkyzb)
                                 {
                                     if (ssbs.Contains("整备质量"))
                                     {
                                         flowzbzl.flowbass.sdpcomm = flowex.sdpcomm;
                                         flowzbzl.flowbass.dpcomm = flowex.dpcomm;
                                     }
                                     if (ssbs.Contains("外廓尺寸"))
                                     {
                                         flowzbzl.flowbass.sdpcommwkcc = flowex.sdpcomm;
                                         flowzbzl.flowbass.dpcommwkcc = flowex.dpcomm;
                                     }
                                 }
                                 else
                                 {
                                     bwkyzb = true;
                                     flowex.gwjysbbhzbzl = szbzljcd;
                                     flowex.gwjysbbhwkcc = swkccjcd;
                                     整备质量与外廓尺寸ToolStripMenuItem1.Visible = true;
                                     整备质量与外廓尺寸ToolStripMenuItem.Visible = true;
                                     flowzbzl = new 安检仪表.TESTZBZL(panel_Width, panel_Height);
                                     flowzbzl.m_mainform = this;
                                     //flowfl.StartPosition = FormStartPosition.CenterParent;
                                     控制流程.gongwei.ifl = 0;
                                     flowzbzl.flowbass = flowex;
                                     //flowzbzl.timerstart();
                                     objyibiaobass.bzbzl = true;
                                     objyibiaobass.f12 = flowzbzl;
                                     objyibiaobass.f11.外廓整备ToolStripMenuItem.Visible = true;
                                     if (ssbs.Contains("整备质量"))
                                     {
                                         flowzbzl.flowbass.sdpcommwkcc = flowzbzl.flowbass.sdpcomm;
                                         flowzbzl.flowbass.dpcommwkcc = flowzbzl.flowbass.dpcomm;
                                         flowzbzl.flowbass.sdpcomm = flowex.sdpcomm;
                                         flowzbzl.flowbass.dpcomm = flowex.dpcomm;
                                     }
                                     if (ssbs.Contains("外廓尺寸"))
                                     {
                                         flowzbzl.flowbass.sdpcommwkcc = flowex.sdpcomm;
                                         flowzbzl.flowbass.dpcommwkcc = flowex.dpcomm;
                                     }
                                 }
                             }
                             #endregion
                             //---------------
                         }
                         //---------------------------------------
                     }

                 }
                 #endregion


                 objyibiaobass.Dock = DockStyle.Fill;
                 objyibiaobass.FormBorderStyle = FormBorderStyle.None;//去掉边框
                 objyibiaobass.TopLevel = false;
                 objyibiaobass.Parent = panel2;
                 panel2.Tag = objyibiaobass;
                 objyibiaobass.Show();
                 if (listflow.Count > 0)
                 {
                     listflow[listflow.Count - 1].bzhgw = true;//最后一个工位标志
                 }

                 objsocket.m_mainform = this;
                 string sipport = objini.ReadValue("工位配置", "通讯").Trim();
                 string[] sipports = sipport.Split(':');
                 if (sipports.Length >= 2)
                 {
                     int iport = 0;
                     int.TryParse(sipports[1], out iport);
                     objsocket.port = iport;
                     objsocket.host = sipports[0];
                     new Thread(objsocket.threadopen).Start();
                 }

                 if (!bdpgy)//如果没有跟尾气灯牌一样的，打开尾气灯牌串口
                 {
                     if (flowwq.sdpcomm.Length > 0)
                     {
                         openCOM(flowwq.sdpcomm, flowwq.dpcomm);
                         flowwq.LedWrite("尾气检测工位", "", 1);
                     }
                 }

                 //多地沟读取配置文件

                 objini = new iniclass();
                 path = System.Windows.Forms.Application.StartupPath + "\\安综检仪表配置.ini";
                 objini.Ini(path);
                 objyibiaobass.f11.objap1.flowbass = new 控制流程.flowcrtl();
                 objyibiaobass.f11.objap2.flowbass = new 控制流程.flowcrtl();
                 objyibiaobass.f11.objap3.flowbass = new 控制流程.flowcrtl();
                 if (objini.ReadValue("多地沟1", "启用").Trim().Contains("是") ? true : false)
                 {

                     sql = string.Format(@"select * from PhotoChannel where channel_line='{0}' and channel_name='底盘检查工位' order by channel_id", 1);
                     dt = objdbbass.GetTable(sql);
                     string stongdaoap = "0";
                     string sjcdap = "0";
                     if (dt.Rows.Count > 0)
                     {
                         sjcdap = dt.Rows[0]["channel_sbbh"].ToString().Trim();
                         stongdaoap = dt.Rows[0]["channel_no"].ToString().Trim();

                     }

                     objyibiaobass.f11.objap1.flowbass.sdpcomm = objini.ReadValue("多地沟1", "灯牌串口设置").Trim();
                     openCOM(objyibiaobass.f11.objap1.flowbass.sdpcomm, objyibiaobass.f11.objap1.flowbass.dpcomm);
                     objyibiaobass.f11.objap1.flowbass.m_mainform = this;
                     objyibiaobass.f11.objap1.flowbass.sgongwei = "地沟工位1";
                     objyibiaobass.f11.objap1.flowbass.sshebei = "地沟";
                     objyibiaobass.f11.objap1.flowbass.LedWrite(objyibiaobass.f11.objap1.flowbass.sgongwei, "", 1);
                     objyibiaobass.f11.objap1.flowbass.ssfAJLW = ssfAJLW;
                     objyibiaobass.f11.objap1.flowbass.sweburl = sweburl;
                     objyibiaobass.f11.objap1.flowbass.sjcz = sjcz;
                     objyibiaobass.f11.objap1.flowbass.sjcbz = sjcbz;
                     objyibiaobass.f11.objap1.flowbass.ssqm = ssqm;
                     objyibiaobass.f11.objap1.flowbass.ssqqzr = ssqqzr;
                     objyibiaobass.f11.objap1.flowbass.lwpt = lwpt;
                     objyibiaobass.f11.objap1.flowbass.photosIP = zpid;
                     objyibiaobass.f11.objap1.flowbass.photosPort = zpdk;//cjm
                     objyibiaobass.f11.objap1.flowbass.initajlw();
                     objyibiaobass.f11.objap1.flowbass.ddgxh = "1";

                     objyibiaobass.f11.objap1.flowbass.gwjysbbh = sjcdap;
                     int.TryParse(stongdaoap, out objyibiaobass.f11.objap1.flowbass.iaptongdao);
                     objyibiaobass.f11.objap1.initcom(objini.ReadValue("多地沟1", "扫描枪串口设置").Trim());
                     //多地沟3", "扫描枪串口设置
                     objyibiaobass.f11.gb1.Visible = true;
                     objyibiaobass.f11.地沟1ToolStripMenuItem.Visible = true;
                     objyibiaobass.f11.下线ToolStripMenuItem.Visible = true;
                 }

                 if (objini.ReadValue("多地沟2", "启用").Trim().Contains("是") ? true : false)
                 {
                     sql = string.Format(@"select * from PhotoChannel where channel_line='{0}' and channel_name='底盘检查工位' order by channel_id", 2);
                     dt = objdbbass.GetTable(sql);
                     string stongdaoap = "0";
                     string sjcdap = "0";
                     if (dt.Rows.Count > 0)
                     {
                         sjcdap = dt.Rows[0]["channel_sbbh"].ToString().Trim();
                         stongdaoap = dt.Rows[0]["channel_no"].ToString().Trim();

                     }

                     objyibiaobass.f11.objap2.flowbass.sdpcomm = objini.ReadValue("多地沟2", "灯牌串口设置").Trim();
                     openCOM(objyibiaobass.f11.objap2.flowbass.sdpcomm, objyibiaobass.f11.objap2.flowbass.dpcomm);
                     objyibiaobass.f11.objap2.flowbass.m_mainform = this;
                     objyibiaobass.f11.objap2.flowbass.sgongwei = "地沟工位2";
                     objyibiaobass.f11.objap2.flowbass.sshebei = "地沟";
                     objyibiaobass.f11.objap2.flowbass.LedWrite(objyibiaobass.f11.objap2.flowbass.sgongwei, "", 1);
                     objyibiaobass.f11.objap2.flowbass.ssfAJLW = ssfAJLW;
                     objyibiaobass.f11.objap2.flowbass.sweburl = sweburl;
                     objyibiaobass.f11.objap2.flowbass.sjcz = sjcz;
                     objyibiaobass.f11.objap2.flowbass.sjcbz = sjcbz;

                     objyibiaobass.f11.objap2.flowbass.ssqm = ssqm;
                     objyibiaobass.f11.objap2.flowbass.ssqqzr = ssqqzr;
                     objyibiaobass.f11.objap2.flowbass.lwpt = lwpt;
                     objyibiaobass.f11.objap2.flowbass.photosIP = zpid;
                     objyibiaobass.f11.objap2.flowbass.photosPort = zpdk;//cjm
                     objyibiaobass.f11.objap2.flowbass.initajlw();
                     objyibiaobass.f11.objap2.flowbass.ddgxh = "2";

                     objyibiaobass.f11.objap2.flowbass.gwjysbbh = sjcdap;
                     int.TryParse(stongdaoap, out objyibiaobass.f11.objap2.flowbass.iaptongdao);

                     objyibiaobass.f11.objap2.initcom(objini.ReadValue("多地沟2", "扫描枪串口设置").Trim());
                     //多地沟3", "扫描枪串口设置
                     objyibiaobass.f11.gb2.Visible = true;
                     objyibiaobass.f11.地沟2ToolStripMenuItem.Visible = true;
                     objyibiaobass.f11.下线ToolStripMenuItem.Visible = true;
                 }

                 if (objini.ReadValue("多地沟3", "启用").Trim().Contains("是") ? true : false)
                 {

                     sql = string.Format(@"select * from PhotoChannel where channel_line='{0}' and channel_name='底盘检查工位' order by channel_id", 3);
                     dt = objdbbass.GetTable(sql);
                     string stongdaoap = "0";
                     string sjcdap = "0";
                     if (dt.Rows.Count > 0)
                     {
                         sjcdap = dt.Rows[0]["channel_sbbh"].ToString().Trim();
                         stongdaoap = dt.Rows[0]["channel_no"].ToString().Trim();

                     }

                     objyibiaobass.f11.objap3.flowbass.sdpcomm = objini.ReadValue("多地沟3", "灯牌串口设置").Trim();
                     openCOM(objyibiaobass.f11.objap3.flowbass.sdpcomm, objyibiaobass.f11.objap3.flowbass.dpcomm);
                     objyibiaobass.f11.objap3.flowbass.m_mainform = this;
                     objyibiaobass.f11.objap3.flowbass.sgongwei = "地沟工位3";
                     objyibiaobass.f11.objap3.flowbass.sshebei = "地沟";
                     objyibiaobass.f11.objap3.flowbass.LedWrite(objyibiaobass.f11.objap3.flowbass.sgongwei, "", 1);
                     objyibiaobass.f11.objap3.flowbass.ssfAJLW = ssfAJLW;
                     objyibiaobass.f11.objap3.flowbass.sweburl = sweburl;
                     objyibiaobass.f11.objap3.flowbass.sjcz = sjcz;
                     objyibiaobass.f11.objap3.flowbass.ssqm = ssqm;
                     objyibiaobass.f11.objap3.flowbass.sjcbz = sjcbz;
                     objyibiaobass.f11.objap3.flowbass.ssqqzr = ssqqzr;
                     objyibiaobass.f11.objap3.flowbass.lwpt = lwpt;
                     objyibiaobass.f11.objap3.flowbass.photosIP = zpid;
                     objyibiaobass.f11.objap3.flowbass.photosPort = zpdk;//cjm
                     objyibiaobass.f11.objap3.flowbass.initajlw();
                     objyibiaobass.f11.objap3.flowbass.ddgxh = "3";

                     objyibiaobass.f11.objap3.flowbass.gwjysbbh = sjcdap;
                     int.TryParse(stongdaoap, out objyibiaobass.f11.objap3.flowbass.iaptongdao);
                     objyibiaobass.f11.objap3.initcom(objini.ReadValue("多地沟3", "扫描枪串口设置").Trim());
                     //多地沟3", "扫描枪串口设置
                     objyibiaobass.f11.gb3.Visible = true;
                     objyibiaobass.f11.地沟3ToolStripMenuItem.Visible = true;
                     objyibiaobass.f11.下线ToolStripMenuItem.Visible = true;
                 }
                 if ((objini.ReadValue("整备质量", "地磅").Trim().Contains("是") ? true : false) && (objini.ReadValue("整备质量", "地磅串口").Trim().Length>0))
                 {
                     string sSetCom = objini.ReadValue("整备质量", "地磅串口").Trim();
                     flowzbzl.initcom(sSetCom);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
         }
        
        public void iniaps()
        {
            
            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            if (objini.ReadValue("多地沟1", "启用").Trim().Contains("是") ? true : false)
            {

            }
            if (objini.ReadValue("多地沟2", "启用").Trim().Contains("是") ? true : false)
            {

            }
            if (objini.ReadValue("多地沟3", "启用").Trim().Contains("是") ? true : false)
            {

            }

        }
        public void sethongwai(System.Windows.Forms.ToolStripLabel pic1, bool bdi)
         {
             try
             {
                 if (!bdi)
                 {

                     pic1.ForeColor = Color.Green;
                 }
                 else
                 {


                     pic1.ForeColor = Color.Red;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
         }

         public void sethongwai(Label pic1, bool bdi)
         {
             try
             {
                 if (!bdi)
                 {

                     pic1.ForeColor = Color.Green;
                 }
                 else
                 {


                     pic1.ForeColor = Color.Red;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
         }

         private void skinButton4_Click(object sender, EventArgs e)
         {
             if (string.IsNullOrWhiteSpace(sdetid))
             {
                 MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                 return;
             }
             if (sdlxjy!="是")
             {
                 MessageBox.Show("动力性检测免检");
                 return;
             }
             flowdlx.flowbass.sDetectID = sdetid;
             flowdlx.ShowDialog();

         }

         private void skinButton5_Click(object sender, EventArgs e)
         {

             if (string.IsNullOrWhiteSpace(sdetid))
             {
                 MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                 return;
             }
             if (syhjy != "是")
             {
                 MessageBox.Show("油耗检测免检");
                 return;
             }
             flowyh.flowbass.sDetectID = sdetid;
             flowyh.ShowDialog();
         }
         string sdetid = "";
         string sdlxjy = "";
         string syhjy = "";

         public void baocunrijiGCSJ(string sname, string sneirong)
         {
             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
             if (!Directory.Exists(smul))
             {
                 Directory.CreateDirectory(smul);
             }
             string path = "";
             path = smul + "\\" + sname + ".ini";

             Ini(path);

             Writue("过程数据", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), sneirong);
         }

         private void 信息录入ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             renyuanshezhi obj = new renyuanshezhi();
             obj.m_mainform = this;
             obj.MdiParent = this.MdiParent;
             // obj.ShowDialog();
             obj.Show();
         }

         private void 设备自检ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             //shebeizijian obj = new shebeizijian();
             //obj.m_mainform = this;
             //obj.ShowDialog();
         }

         private void 串口及通道配置ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             TongDaoSheZhi obj = new TongDaoSheZhi();
             obj.MdiParent = this.MdiParent;
             obj.setmainform(this);
             // obj.ShowDialog();
             obj.Show();
         }

         private void 信号标定ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             BiaoDing obj = new BiaoDing();
             obj.m_mainform = this;
             obj.ShowDialog();
         }

         private void 举升升ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             DAC.Lift(true);
         }

         private void 举升降ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             DAC.Lift(false);
         }

         private void 车辆调度ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             //bdiaodu = true;
             objyibiaobass.select("调度");
             bpanelshow = true;
             showpanel();
             //skinTabControl1.Visible = true;
             //panel1.BackgroundImage = null;
             //panel1.Visible = true;
         }

         private void 综安检ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             gwpz obj = new gwpz();
            
             obj.ShowDialog();

           
         }

         private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             string path = "";
             path = System.Windows.Forms.Application.StartupPath + path + "\\数据库设置.ini";
             string path1 = string.Format(@"{0}", path);
             Ini(path1);
             string sjkwqip = ReadValue("尾气设置", "数据库IP");
             if (sjkwqip.Length > 0)
             {
                 guanyu obj = new guanyu();
                 obj.ShowDialog();
             }
             else
             {
                 基类窗体.guanyuanjian obj = new 基类窗体.guanyuanjian();
                 obj.ShowDialog();
             }

         }
        public string sobdshifou="0";
        public string sgkfjc = "0";

         private void 车速ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {

                 objyibiaobass.select("车速");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开车速仪表界面", ex.Message.ToString());
                 }
             }
             
         }

         private void 轮重ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("轮重");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开轮重仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 制动ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             try
             {
                 objyibiaobass.select("制动");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开制动仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 灯光ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             try
             {
                 objyibiaobass.select("灯光");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开灯光仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 侧滑ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             try
             {
                 objyibiaobass.select("侧滑");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开侧滑仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 地沟ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             try
             {
                 objyibiaobass.select("地沟");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开地沟仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 悬架ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("悬架");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开悬架仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 动力性ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("动力性");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开动力性仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 燃油经济性ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("油耗");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开油耗仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 平板制动ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("平板");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开平板仪表界面", ex.Message.ToString());
                 }
             }

         }
         public void SaveErrorLog(string type, string content)
         {
             var sql = "";
             sql = string.Format(@"insert into ErrorLog (Log_ID,
                                                    Log_Type,
                                                    Log_Content,
                                                    Log_Date) 
                                                    values ('{0}',
                                                    '{1}',
                                                    '{2}',
                                                    '{3}')",
                                                     Guid.NewGuid(),
                                                     type,
                                                     content,
                                                     DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
           objdbbass.InsertDB(sql);
         }

         private void 仪表基类ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             //panel2.Visible = true;
         }

         private void 仪表ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             //objyibiaobass.select("制动");
             //objyibiaobass.ShowDialog();
         }

         private void mainform_FormClosing(object sender, FormClosingEventArgs e)
         {
             objsocket.send("关闭软件");
         }
         public bool bpanelshow = false;

         private delegate void FlushClient();//代理
         public void showpanel()
         {
             if (this.panel2.InvokeRequired)//等待异步
             {
                 FlushClient fc = new FlushClient(showpanel);
                 this.Invoke(fc);//通过代理调用刷新方法
             }
             else
             {
                 if (bdiaodu && !bpanelshow)
                 {
                     objyibiaobass.select("调度");
                 }
                 else
                 {
                     this.panel2.Visible = bpanelshow;
                 }
             }
         }

         private void 整备质量与外廓尺寸ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("整备质量");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开整备质量仪表界面", ex.Message.ToString());
                 }
             }

         }

         private void 调度控制ToolStripMenuItem_Click(object sender, EventArgs e)
         {

              try
             {
                 objyibiaobass.select("调度");
                 bpanelshow = true;
                 showpanel();
             }
              catch (Exception ex)
              {
                  if (!(ex is System.Threading.ThreadAbortException))
                  {
                      SaveErrorLog("打开调度仪表界面", ex.Message.ToString());
                  }
              }
         }

         private void 车速ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("车速");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开车速仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 轮重ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("轮重");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开轮重仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 制动ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("制动");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开制动仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 灯光ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("灯光");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开灯光仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 侧滑ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("侧滑");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开侧滑仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 地沟ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("地沟");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开地沟仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 悬架ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("悬架");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开悬架仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 动力性ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("动力性");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开动力性仪表界面", ex.Message.ToString());
                 }
             }
         }

         private void 油耗ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("油耗");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开油耗仪表界面", ex.Message.ToString());
                 }
             }

         }

         private void 平板制动ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("平板");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开平板仪表界面", ex.Message.ToString());
                 }
             }

         }

         private void 整备质量与外廓尺寸ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             try
             {
                 objyibiaobass.select("整备质量");
                 bpanelshow = true;
                 showpanel();
             }
             catch (Exception ex)
             {
                 if (!(ex is System.Threading.ThreadAbortException))
                 {
                     SaveErrorLog("打开整备质量仪表界面", ex.Message.ToString());
                 }
             }

         }

         /// <summary>
         /// 是否为日期型字符串
         /// </summary>
         /// <param name="StrSource">日期字符串(2008-05-08)</param>
         /// <returns></returns>
         public bool IsDate(string StrSource)
         {
             return System.Text.RegularExpressions.Regex.IsMatch(StrSource, @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
         }
         /// <summary>
         /// 是否为时间型字符串
         /// </summary>
         /// <param name="source">时间字符串(15:00:00)</param>
         /// <returns></returns>
         public bool IsTime(string StrSource)
         {
             return System.Text.RegularExpressions.Regex.IsMatch(StrSource, @"^((20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$");
         }

         /// <summary>
         /// 是否为整数
         /// </summary>
         /// <param name="source">0-9</param>
         /// <returns></returns>
         public bool IsInt(string StrSource)//
         {
             return System.Text.RegularExpressions.Regex.IsMatch(StrSource, @"^[0-9]\d*$");
         }

         /// <summary>
         /// 是否为IP地址字符串
         /// </summary>
         /// <param name="source">IP地址字符串(192.168.1.1)</param>
         /// <returns></returns>
         public bool IsIp(string StrSource)
         {
             return System.Text.RegularExpressions.Regex.IsMatch(StrSource, @"^(\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b)$");
         }

         private void 标定自检ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             shebeibiaoding obj = new shebeibiaoding();
             obj.m_mainform = this;
             obj.ShowDialog();
         }

         private void 尾气自检ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             shebeizijian obj = new shebeizijian();
             obj.m_mainform = this;
             obj.ShowDialog();
         }

         private void 查看设备自检状态ToolStripMenuItem_Click(object sender, EventArgs e)
         {

             check();
         }
         public bool getdatezj(string sdate)
         {
             DateTime dtimezj = DateTime.Now;
             DateTime.TryParse(sdate, out dtimezj);
             if ((DateTime.Now - dtimezj).TotalDays > 1)
             {
                 return false;
             }
             return true;
             //if (DateTime.TryParse(stimehxqy, out hxdtime) && DateTime.TryParse(stimeyqfq, out hxdtime))
             //{
             //    if ((DateTime.Now - hxdtime).TotalDays > 1)
             //    {
             //        HXqy = false;
             //        bzijian = false;
             //    }
             //}
         }
         public string check()
         {

             string paths = "";
             paths = System.Windows.Forms.Application.StartupPath + paths + "\\系统信息.ini";
             string path2 = string.Format(@"{0}", paths);
             Ini(path2);
             string fenxiyinameQY = ReadValue("串口设置", "废气仪厂家");
             string fenxiyinameCY = ReadValue("串口设置", "不透光厂家");

             string path = "";
             string stimehxqy = "";
             string stimehxcy = "";
             string stimeyr = "";
             string stimeyqfq = "";
             string stimeyqbtg = "";
             string stimeyqcaiyou = "";
             path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
             string path1 = string.Format(@"{0}", path);
             Ini(path1);
             stimehxqy = ReadValue("汽油恒加载检定", "检定时间");
             stimehxcy = ReadValue("柴油加载滑行10kw", "检定时间");
             stimeyqfq = ReadValue("废气仪检定", "检定时间");
             stimeyqbtg = ReadValue("不透光检定", "检定时间");
             stimeyr = ReadValue("台架预热", "检定时间");
             stimeyqcaiyou = ReadValue("柴油分析仪检定", "检定时间");

             //objini.Writue("柴油分析仪检定", "检定时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

             bool bzijian = true;
             bool HXqy = true;
             bool HXcy = true;
             bool feiqi = true;
             bool ydj = true;
             bool yr = true;
             bool caiyounox = true;
             if (fenxiyinameQY.Length < 1)
             {
                 if (!getdatezj(stimehxqy))
                 {
                     HXqy = false;
                     bzijian = false;
                 }
                 if (!getdatezj(stimeyqfq))
                 {
                     feiqi = false;
                     bzijian = false;
                 }

             }
             if (fenxiyinameCY.Length < 1)
             {
                 if (!getdatezj(stimehxcy))
                 {
                     HXcy = false;
                     bzijian = false;
                 }
                 if (!getdatezj(stimeyqbtg))
                 {
                     ydj = false;
                     bzijian = false;
                 }
                 if (!getdatezj(stimeyqcaiyou))
                 {
                     caiyounox = false;
                     bzijian = false;
                 }
             }
             if (!getdatezj(stimeyr))
             {
                 yr = false;
                 bzijian = false;
             }
             if (!bzijian)
             {
                 JDTip jd = new JDTip(HXcy, HXqy, feiqi, caiyounox, ydj, yr);
                 jd.m_mainform = this;
                 jd.ShowDialog();
             }
             return "";
         }

         private void mainform_Shown(object sender, EventArgs e)
         {
             x = this.Width;
             y = this.Height;
             setTag(this);
             this.panel1.BackgroundImage = Image.FromFile(@"./ico/广州维柯.jpg");
             this.panel1.BackgroundImageLayout = ImageLayout.Stretch;
             //this.BackgroundImage = Image.FromFile(@"./ico/广州维柯.jpg");
             MethodInvoker ln = new MethodInvoker(iniform);
             this.BeginInvoke(ln);
         }
         public void Savelog(string section, string sneirong, string sjylsh, string hphm)
         {

             string syy = DateTime.Now.ToString("yyyy");
             string smm = DateTime.Now.ToString("MM");
             string sdd = DateTime.Now.ToString("dd");
             string smul = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\{5}", System.Windows.Forms.Application.StartupPath, "日志信息", syy, smm, sdd, hphm);
             if (!Directory.Exists(smul))
             {
                 Directory.CreateDirectory(smul);
             }
             string path = "";
             path = string.Format("{0}\\{1}_{2}.log", smul, hphm, sjylsh);
             Ini(path);

             Writue("[日志]", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "【" + section + "】", sneirong);

         }
         public void inserttongji(string slsh, string haopai, string jccs)//YCY  CZY
         {
             try
             {

                 string SQL = string.Format(@"CREATE TABLE [dbo].[TONGJI](
	        [DETECT_ID] [nvarchar](50) NOT NULL,
	        [PLATE_ID] [nchar](10) NULL,
	        [testtimes] [nchar](10) NULL,
	        [dlsj] [datetime] NULL,
	        [DET_MDRIVE] [nchar](10) NULL,
	        [ASM_CZY] [nchar](10) NULL,
             )");
                 objbass.objdb.InsertDB(SQL);
             }
             catch
             {

             }
             string time = DateTime.Now.ToString();
             string sql = string.Format(@"select * from TONGJI where  DETECT_ID='{0}' and testtimes='{1}'", slsh, jccs);
             DataTable dt1 = objbass.objdb.GetTable(sql);
             if (dt1.Rows.Count > 0)
             {
                 string sqlxzxx = string.Format(@"update TONGJI set  
                                                DET_MDRIVE='{0}',
                                                ASM_CZY='{1}'                                          
                                                where  DETECT_ID='{2}' ",
                                                InspectionDriver,
                                                InspectionOperator,
                                                slsh);

                 objbass.objdb.InsertDB(sqlxzxx);

             }
             else
             {

                 string sqlxzxx = string.Format(@"insert into  TONGJI  (DETECT_ID ,PLATE_ID,testtimes,dlsj,DET_MDRIVE,ASM_CZY)values('{0}','{1}','{2}','{3}','{4}','{5}')", slsh, haopai, jccs, time, InspectionDriver, InspectionOperator);
                 objbass.objdb.InsertDB(sqlxzxx);
             }


         }
    }
}
